Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Fix the SSH "Connection reset by peer" Error

The server closed your SSH session. Check the network, the SSH service, the firewall and the SSH settings.

VPS and Cloud Servers2 min read3 steps4 screenshots

What the error means

"Connection reset by peer" means the other side of the connection closed it. Typical causes:

  1. Network problems: lost packets, heavy traffic or a firewall.
  2. Server problems: low resources, a stopped SSH service or limits in the SSH settings.
  3. Client problems: a wrong SSH config or old software.

Step 1: Check the network

ping server_address

If there is no reply or many packets are lost, the problem is in the network.

Step 2: Check the SSH service

On the server (use the console if you cannot log in):

sudo systemctl status ssh
The status of the SSH service

On CentOS and Red Hat the service is called sshd. If it is not running, start it:

sudo systemctl start ssh

Read the log for hints (/var/log/secure on CentOS, /var/log/auth.log on Ubuntu):

sudo tail -f /var/log/secure

Step 3: Check the client config

Look at your SSH client file for wrong settings:

nano ~/.ssh/config

Step 4: Check the firewall

Allow SSH in the firewall:

sudo ufw allow 22/tcp

or:

sudo ufw allow ssh

If you changed the SSH port, allow that port instead.

Step 5: Check the SSH server settings

Open the server config:

sudo nano /etc/ssh/sshd_config

Check or change these values:

MaxAuthTries 6
MaxAuthTries in sshd_config
ClientAliveInterval 60
ClientAliveCountMax 3
ClientAlive settings
MaxStartups 10:30:100
MaxSessions 100
MaxStartups and MaxSessions

Restart the service:

sudo systemctl restart sshd

Step 6: Ask SSH to explain

Run the client in verbose mode. It prints each step of the connection:

ssh -v user@server

Add more v letters (-vvv) for more detail.

Good to know

  • SSH keys are safer than passwords.
  • Keep the SSH client and server updated.
  • Check CPU, memory and disk use of the server. A busy server may drop connections.
  • Try another user account to see if the problem is about one account.

Quick recap

  • Test the network, the SSH service and the firewall first.
  • Adjust ClientAliveInterval, MaxStartups and MaxSessions.
  • Use ssh -v to see where the connection fails.