What does "Connection reset by peer" mean?
The other end sent a TCP reset, an abrupt "this connection is over". Unlike a timeout, where packets vanish, a reset is a deliberate reply. With SSH it shows up in a few shapes: kex_exchange_identification: read: Connection reset by peer right after connecting, a reset during authentication, or client_loop: send disconnect: Connection reset by peer after a session sat idle. Each shape points to a different cause.
Which cause fits my symptom?
| When it happens | Likely cause | First check |
|---|---|---|
| Instantly, before any prompt | Ban list, throttling, broken sshd | fail2ban status, sshd log |
| During key exchange, on one network only | MTU or middlebox issue | Try another network or lower MTU |
| After minutes of idling | NAT or firewall dropping idle flows | Client keepalives |
| During big transfers | Unstable path, offload bugs | Retry with compression off, check NIC errors |
Was my address banned?
Very often, yes. fail2ban and similar tools watch the auth log and block addresses after a few failed logins. Your own typos, or a script with an old password, can ban you. Depending on the action configured, the block shows up as a reset or as a timeout. From another address, or a still-open session, check and lift the ban:
fail2ban-client status sshd fail2ban-client set sshd unbanip 203.0.113.58
Add your office or home address to ignoreip in /etc/fail2ban/jail.local so it never happens again. If you use nftables sets for blocking instead, nft list set inet filter blocklist shows the entries.
Is sshd throttling new connections?
sshd limits how many connections may sit in the unauthenticated stage at once. The default MaxStartups 10:30:100 means: above 10 pending logins, drop 30 percent of new ones at random, rising to all of them at 100. A burst of bot attempts, or your own automation opening many sessions in parallel, fills that pool and legitimate connections get reset. The server logs a line like beginning MaxStartups throttling.
grep -i maxstartups /var/log/auth.log | tail -3 # Debian, Ubuntu journalctl -u sshd | grep -i maxstartups | tail -3 # Rocky, AlmaLinux
Raising the limit to something like MaxStartups 30:50:120 in a drop-in helps busy automation. Cutting bot traffic helps more: move the port, allow SSH only from known addresses or use multiplexing on the client so one connection carries many sessions. OpenSSH 9.8 and later also add PerSourcePenalties, which slows down sources that keep failing.
Is sshd itself broken?
If sshd cannot load its host keys or its configuration, it may accept TCP and then drop it immediately. That happens after a careless cleanup of /etc/ssh, or when a config file was edited by hand. On the server, run:
sshd -t ls -l /etc/ssh/ssh_host_*_key ssh-keygen -A # recreates any missing host keys with default settings
Recreated host keys have new fingerprints, so every client will warn once. Restart the service after the fix, keeping your current session open.
Why do idle sessions get reset?
Home routers, office firewalls and mobile networks forget quiet TCP flows after a few minutes. When your next keystroke arrives, the device has no record of the flow and answers with a reset. Keepalives solve it by sending a tiny encrypted packet at intervals. Put this in ~/.ssh/config on your computer:
Host *
ServerAliveInterval 45
ServerAliveCountMax 4
The server side has a matching pair, ClientAliveInterval and ClientAliveCountMax, which also cleans up sessions whose clients vanished.
What if it only fails from one network?
Then the problem sits on that path. Some networks mishandle large packets, and the key exchange is where SSH first sends big ones, especially with the newer post-quantum hybrid algorithms that make the first packets larger. Test with a smaller MTU on your side, for example sudo ip link set dev wlan0 mtu 1380, and try again. If that works, the fix belongs to the network owner, or to a VPN that clamps packet size. Corporate proxies that inspect traffic sometimes reset SSH outright; a different port such as 443 can help there, if nothing else on the machine uses it.
What if nothing on the server explains it?
Collect evidence from both ends at the same moment: ssh -vvv on the client and tcpdump -ni any port 22 and host 203.0.113.58 on the server. If the server never sees your packets, the reset comes from somewhere in between. Open a ticket in the panel with the client's public address, the time and the verbose output, so the network side can be checked.
Keep Reading
Fix "Connection refused"
Work out why port 22 says no: sshd stopped, wrong port, a firewall reject rule, a loopback-only listener or a machine still installing.
OpenHarden SSH on Linux
A practical hardening list for sshd on a fresh dedicated box: keys, users, rate limits, firewall scope and an outside audit.
OpenThe SSH config file
Turn long ssh command lines into short aliases with ~/.ssh/config: hosts, ports, keys, jump hosts, keepalives and connection sharing.
OpenEdge DDoS filtering
How common volumetric attacks are filtered at the network edge before they reach your ports, and what you still handle on the box.
OpenFAQ
Quick Answers
Usually a ban list such as fail2ban, MaxStartups throttling or sshd failing to load its keys. The server auth log shows which.
Set ServerAliveInterval and ServerAliveCountMax in your SSH client config so small keepalive packets keep the flow alive.
An sshd setting that limits unauthenticated connections. When it is exceeded, new connections are dropped at random.
Yes. A reject rule sends a reset or an error, while a drop rule makes the client wait for a timeout.
From another address or session run fail2ban-client set sshd unbanip followed by your address, then add it to ignoreip.