60

I created a passwordless ssh connection to my remote server from my mac. It worked(!) and then I closed my terminal, re-opened it, tried again, and got the following (username, my_ip are not real):

ssh -vvv username@my_ip
OpenSSH_7.2p2, LibreSSL 2.4.1
debug1: Reading configuration data /Users/Me/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 53: Applying options for *
debug2: resolving "my_ip" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to my_ip [my_ip] port 22.
debug1: Connection established.
debug1: identity file /Users/Me/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Mes/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Me/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2
ssh_exchange_identification: read: Connection reset by peer

When I checked my .ssh folder, id_rsa was there but none of the others were. From the error, it looks like I need to somehow create these files but am not sure how to do so.

Any help would be appreciated.

2
  • 2
    Is there an actual problem? For example, are you actually failing to log in? Could you edit your question to include the complete debug output, instead of just the first part?
    – Kenster
    Nov 8, 2016 at 22:18
  • 1
    Yes; my apologies! I can't log in -- and I had left off the last (and perhaps most important?) line earlier.
    – Eric
    Nov 8, 2016 at 22:28

6 Answers 6

70
debug1: key_load_public: No such file or directory

The line above is not error, but just simple debug log saying that ssh client is not able to find separate public key (named ~/.ssh/id_rsa.pub). This file is not needed to connect to the remote server, but it can be useful.

The actual error

ssh_exchange_identification: read: Connection reset by peer

points to error in server configuration. The server is running, but fails to accept the SSH connection. Check the server log for more information. Similar problems

2
  • 1
    That link was very helpful. And, it turns out that I was in fact blacklisted (I had ssh'ed into my server too many times while I was testing something out.)
    – Eric
    Nov 8, 2016 at 22:47
  • 2
    My problem was a Bastion host had changed the IP address and the known_hosts was incorrect on my Mac... It showed @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @... It shows the line number by ~/.ssh/known_hosts:238. So, I removed that line, 238 in this case, from the known_hosts file on my Mac and I tried to connect again successfully. Dec 14, 2017 at 0:04
5

Problem: bastion host IP mismatch on ~/.ssh/known_hosts

I had the known_hosts file old as the IP address of the bastion changed...

$ ssh 10.82.49.24
ssh_exchange_identification: Connection closed by remote host

Did not give me any information. Looking at the verbose output leads to the same thing:

$ ssh -v 10.82.49.24
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/mdesales/.ssh/config
debug1: /Users/mdesales/.ssh/config line 1: Applying options for 10.82.*.*
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec ssh -q -W 10.82.49.24:22 ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/xxxconfig-xxxx.pem
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/xxxconfig-xxxx.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: permanently_drop_suid: 1647059022
ssh_exchange_identification: Connection closed by remote host

At this point, since it is a proxy to another host through the bastion, I could see the bastion being a problem:

$ ssh ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Z8X1UlIgQ94BKJ7NA/oQi7v0NL4IlFeO7Ou4j76Zphk.
Please contact your system administrator.
Add correct host key in /Users/mdesales/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/mdesales/.ssh/known_hosts:238
ECDSA host key for ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com has changed and you have requested strict checking.
Host key verification failed.

Solution

Removing the entry on line 238 solved the problem... I could ssh to the bastion and I could ssh to the hosts.

$ vim /Users/mdesales/.ssh/known_hosts

$ ssh ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem
The authenticity of host 'ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com (34.x.x.y)' can't be established.
ECDSA key fingerprint is SHA256:Z8X1UlIgQ94BKJ7NA/oQi7v0NL4IlFeO7Ou4j76Zphk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-user@bastion-vpc-xxxxxx.config-yyyyyyy.com -i ~/.ssh/xxxconfig-xxxx.pem,34.213.y.x' (ECDSA) to the list of known hosts.
********************************************************************************
This is a private computer system containing information that is proprietary
and confidential to the owner of the system.  Only individuals or entities
authorized by the owner of the system are allowed to access or use the system.
Any unauthorized access or use of the system or information is strictly
prohibited.

All violators will be prosecuted to the fullest extent permitted by law.
********************************************************************************
Last login: Wed Aug  2 20:35:55 2017 from 10.81.31.115
[ec2-user@ip-10-82-50-142 ~]$ 
2

There was the same problem. Decided her like that:

chmod 0600 /home/<user>/.ssh/*
1
  • This fixed my problem because I had copied my keys from an older computer to this new one and permissions were not set correctly! Thanks! Feb 29, 2020 at 6:11
1

Same problem, just post the solution here

Remove Your IP From /etc/hosts.deny using :

nano /etc/hosts.deny
1

Happened to me today.

Fixed by disconnecting my WLAN and reconnecting. Yes, it sounds stupid and it is stupid but at least on one WLAN this has happened with no any good reason.

-1

I suddenly got this same issue after a long period of using remote ssh successfully with a working configuration. The issue came after the host froze and was exposed to a hard restart.

I got it working again by renaming (thereby resetting) the .vscode and .vscode-server directories. This lead a fresh installation of the remote plugin/adon and a clean configuration and then the remote ssh connection was possible again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .