When I tried to connect to the server via SSH, I'm getting the following error,

[root@oneeighty ~]# ssh -vvv -p 443 root@xxx.xxx.xxx
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to xxx.xxx.xxx [IP] port 443.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
ssh_exchange_identification: read: Connection reset by peer

I have checked the SSH configuration on server and client and there are no issues.

Restarted the SSH Service on Server and then restarted the server/client, but the issues is not resolved.

  • You can allow ssh connection by firewall User-interface (some providers allow that) or If you have any alternative method to login (Ex. digitalocean provide a console button ) you can run below command sudo ufw allow ssh sudo ufw allow 22
    – BSB
    Feb 8, 2019 at 5:41

9 Answers 9


This can be a result of number of things.

Few things you can quickly try are as follows,

  • Look in /etc/hosts.deny for any entry like sshd: ALL
  • Perhaps, add sshd: ALL to /etc/hosts.allow

  • It is possible that your SSHD's HostKeys are corrupt. They're present in /etc/ssh/ directory. You may delete them and restart sshd and it shall re-generate them. In case it gives an errors, please use the following commands

    $ ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    $ ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
    $ ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
    $ /etc/init.d/sshd start
  • on /etc/hosts.deny file and /etc/hosts.allow, all the lines are commented.
    – Senthil G
    Nov 3, 2012 at 14:13
  • 1
    Please add sshd: ALL to hosts.deny to check if that helps.
    – vagarwal
    Nov 4, 2012 at 14:30

The next line in the debug should look like:

debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu7

You've confirmed on StackOverflow that you're using NATing/port forwarding from an external IP address. You've also verified that you can ssh from the local box to itself. As sshing locally to port 443 works then you need to verify the port mapping works.


  1. SSH from another box in the same subnet
  2. Run iptables -L and check that port 443 is open or INPUT and OUTPUT is set to ACCEPT
  3. Run tcpdump -A -s 0 port 443 and then try sshing to the external IP. You should see data arrive with source address of the router

FWIW, I am running Ubuntu 14.04 on AWS. The issue was fixed by SSHing through their Java Web client, and running sudo service apache2 start. I just wanted my website to be back up, but it also fixed the SSH access. No idea why, but I am not complaining.

  • same issue here. my session was unresponsive for no reason and i could not reconnect through putty. using the web client did whatever magic to allow my connection through putty to work again.
    – AndrewK
    Jun 6, 2016 at 18:43

Check allowed.hosts on the server you are trying to connect to, also any iptables rules it's running.


The Issue has been resolved.
The Problem is on the Load balancers that we have on our network. The Issue is resolved on restarting the Load balancers.

  • Hi I know this is super old but can you remember any details? I may be facing a similar issue. Do you know what kind of load balancer it was and if it was a know bug?
    – montjoy
    Dec 16, 2021 at 21:41

I faced similar issue today as suddenly the ssh access to a VM was denied with same message. ssh -v (at client) and sshd -d (at server) did not help much. The problem in my case started due to changed in firewall/iptable settings which I did for some demo of LAMP stack usage.

I used system-config-firewall-tui to enable firewall and selected only httpd from there which blocked all other services except httpd.

So as a solution to this either add permissions to sshd by

  • updating iptable conf settings OR
  • Selecting sshd from system-config-firewall-tui OR
  • Disabling firewall OR
  • Stop iptable service (rhel6, also remove it from chkconfig) service iptables stop

ssh works perfectly fine now !!!


For me, I to allow sshd connections in /etc/hosts file.

vi /etc/hosts.allow
and add 

sshd: ALL

The way I solved the problem is, I went to the host machine and ran few commands

sudo mkdir /var/run/sshd

sudo chmod 755 -R /var/run/sshd

sudo service ssh restart

I got connected to the machine after that.


First purging openssh-* (openssh-server and openssh-client)

apt-get --purge remove openssh-*

removing /home/username/.ssh directory

rm -rf /home/username/.ssh 

then install your openssh-server and openssh-client

apt-get install openssh-server openssh-client
  • 3
    No, not even close, the OP's answer says what the problem was. You answer is specific to distros that use apt, the OP was using RHEL. Removing and reinstalling a package is almost never the solution.
    – user9517
    Apr 10, 2014 at 6:17
  • Did you do all this on the local or the remote server?
    – Jonathan
    Sep 22, 2016 at 18:47

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