Cannot connect to SSH: Read from socket failed: Connection reset by peer

Written by - 0 comments

Published on July 23rd 2014 - Listed in Linux


Cloned an LXC container from an existing one and then tried to connect to the new LXC through SSH and got this error:

ssh lxc24
Read from socket failed: Connection reset by peer

Logged in through lxc-console, the following error found in /var/log/auth.log describes the source of the problem pretty clear:

lxc24 login[1619]: pam_unix(login:session): session closed for user root
lxc24 sshd[1913]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
lxc24 sshd[1913]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
lxc24 sshd[1913]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

 Somehow during the clone process the host keys were removed. I simply recreated them using:

ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_key
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -b 1024 -t dsa -f /etc/ssh/ssh_host_dsa_key

or as a quicker alternative, run dkpg-reconfigure openssh-server (thanks Fabien):

dpkg-reconfigure openssh-server

And the SSH login worked again (magic! lol):

ssh lxc24
Linux lxc24 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u1 x86_64



Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.