I installed openssh using below command

apt-get install openssh-server openssh-client

I'm trying to create ssh connection to localhost.

ssh user@localhost

I'm getting below error

Connection reset by port 22

How to resolve this error?


Try regenerating the host keys:

sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server

You can get more debug information from ssh with the -v option, as well as looking in the ssh server log, for debian/ubuntu, this is /var/log/auth.log

| improve this answer | |
  • I have seen this suggestion elsewhere, but am confused, is this command supposed to be run on the host machine or client? Am I just out of luck if ssh is my only means of accessing the host? – HowlingFantods May 27 '18 at 23:20
  • It needs to be done on the host server. You'll need some other way to get remote access if ssh is currently inoperable. kvm-over-ip, ipmi console, or rescue boot disk all come to mind. – Andrew Domaszek Jun 7 '18 at 14:19
  • 2
    You can also use ssh-keygen -A -f / to regenerate the host keys. – Rakete1111 Jun 13 '19 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.