kex_exchange_identification: Connection Reset Fix (2026)

SSH fails with kex_exchange_identification: read: Connection reset by peer? TCP worked, sshd hung up. Find which of 6 causes it is, with tested checks.

14 min read

You run ssh and it dies before asking for anything:

yaml

kex_exchange_identification: read: Connection reset by peer
Connection reset by 203.0.113.10 port 22

or its sibling:

yaml

kex_exchange_identification: Connection closed by remote host
Connection closed by 203.0.113.10 port 22

Both mean the same thing: your TCP connection reached something on port 22, and that something hung up before the SSH conversation started. It is not a key problem, not a password problem and not a cipher mismatch. Authentication never began.

That narrows it down a lot. This guide walks through the six causes that produce this error, how to tell them apart from the client and the server, and the fix for each. Every client message quoted below was reproduced in a lab: an OpenSSH 9.6p1 client (Ubuntu 24.04) against a throwaway sshd and a few fake services on 127.0.0.1.

Quick Summary: What You’ll Learn

  • What kex_exchange_identification actually refers to, and why “reset by peer” and “closed by remote host” are the same failure.
  • How this error differs from “Connection refused” and “Connection timed out”.
  • A five-minute diagnosis path: ssh -v, nc, and the server-side checks.
  • The six usual causes: MaxStartups, PerSourcePenalties, hosts.deny, a stale sshd after an upgrade, something other than sshd on the port, and middleboxes.
  • What to change for each, without locking yourself out.

What does “kex_exchange_identification: Connection reset by peer” mean?

Every SSH connection starts with a plain-text line from each side, the identification string. When you connect to an OpenSSH server, the first thing it sends is something like:

bash

SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20

kex_exchange_identification is the client function that sends its own identification string and reads the server’s. It runs right after the TCP handshake and before key exchange, host key checks or authentication.

So the error tells you two things:

  • TCP worked. The client connected to an open port. A firewall dropping your SYN or nothing listening would give you a different error.
  • The other side ended the connection before sending a valid SSH banner. Either it closed cleanly (Connection closed by remote host) or it aborted with a TCP reset (read: Connection reset by peer).

Which of the two you see is mostly timing, not cause. In the lab, a fake server that accepted the connection and closed it immediately produced the reset version, because the client’s banner was already waiting unread in the server’s socket, and closing a socket with unread data sends a RST. The same fake server reading the client’s banner first and then closing produced the “closed” version. Treat the two messages as one error.

One version detail: with the 9.6 client, a clean close printed only Connection closed by 127.0.0.1 port 2302 at the default log level. The kex_exchange_identification: Connection closed by remote host line only appeared with ssh -v. If you have a terse “Connection closed by … port 22” right after connecting, you are probably looking at the same failure.

How is this different from “Connection refused” and “Connection timed out”?

The three errors fail at different points, and that is the fastest way to know where to look. Here is what the lab client printed for each:

  • Nothing listening on the port: ssh: connect to host 127.0.0.1 port 2304: Connection refused. The TCP handshake itself was rejected.
  • Packets silently dropped: ssh: connect to host ... port 22: Connection timed out. No TCP handshake at all, usually a firewall or routing problem.
  • Port open, peer hangs up before the banner: kex_exchange_identification: read: Connection reset by peer. TCP worked, SSH didn’t start.
  • Port open, peer never says anything: Connection timed out during banner exchange (with ConnectTimeout=5 in the lab). TCP worked, but nothing sent a banner.

The first two are covered in depth in SSH connection refused vs timeout. This article is about the last two: the cases where the network path is fine and the problem is whatever answers on the port.

How do you find which cause you have?

Run these from the client first, then on the server if you have another way in (console, a second session that is still open, a cloud serial console).

Step 1: confirm the handshake with ssh -v

bash

ssh -v [email protected]

Look for this line before the error:

yaml

debug1: Connection established.
kex_exchange_identification: read: Connection reset by peer

Connection established confirms TCP got through. If you never see it, you have a refused or timeout problem instead.

Step 2: look at what is actually answering

bash

nc -w 5 server.example.com 22

A healthy OpenSSH server prints its banner straight away:

bash

SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20

Three other outcomes are useful too:

  • The connection closes with no output: something accepted the connection and dropped it. Go to the server-side checks below.
  • You get HTTP, a TLS error or some other text: the port is served by something that isn’t sshd. In the lab, pointing ssh at an HTTP service gave banner line 0: HTTP/1.1 400 Bad Request in ssh -v output, followed by kex_exchange_identification: Connection closed by remote host.
  • It hangs with no output: something accepted the connection but never speaks, the “banner exchange” timeout case.

Step 3: try from a different source address

If it works from another network (a phone hotspot, a different server, a VPN), the server is reacting to your address. That points at penalties, access lists or a ban tool, not at sshd being broken.

Step 4: read the server side

On the server, check that sshd is the process listening, read its log for the time of your attempt, and print the effective settings:

bash

sudo ss -tlnp | grep ':22 '
sudo journalctl -u ssh --since "10 min ago"     # Debian/Ubuntu; the unit is "sshd" on RHEL, Fedora, Arch
sudo sshd -T | grep -iE 'maxstartups|persource|logingracetime'

sshd -T prints the configuration sshd will actually use, after includes and defaults. Keys come out in lowercase (a default config shows maxstartups 10:30:100), so grep case-insensitively.

Is sshd dropping you for too many unauthenticated connections?

This is a frequent cause on busy or internet-facing servers. The sshd_config(5) man page defines MaxStartups as “the maximum number of concurrent unauthenticated connections to the SSH daemon. Additional connections will be dropped until authentication succeeds or the LoginGraceTime expires for a connection.”

The default is 10:30:100: once 10 connections are waiting to authenticate, sshd starts refusing new ones with a 30% probability, rising linearly until every attempt is refused at 100. On a server reachable from the internet, password-guessing bots alone can hold those slots. It also bites legitimate automation: a deploy tool or Ansible run that opens dozens of connections at once can push itself over the threshold, which shows up as random hosts failing with this error while others succeed.

What to do:

  • Find out if you’re near the limit. Count unauthenticated connections in the server log and in ss -tn state established '( sport = :22 )' during the failure.
  • Cut the background noise first. Move password authentication off, restrict port 22 to known ranges with a firewall or security group, or put SSH behind a bastion with ProxyJump. Fewer bots means more free slots.
  • Shorten LoginGraceTime (default 120 seconds) so stuck handshakes release their slot sooner.
  • Raise MaxStartups carefully if the load is your own automation, for example MaxStartups 30:30:100. Raising it on an internet-facing server mostly gives bots more room, so fix exposure first.
  • Throttle the client side. Lower the parallelism in your deploy tool, or reuse connections with ControlMaster/ControlPersist.

PerSourceMaxStartups (default none) applies the same idea per source address, on top of MaxStartups. If someone set it low, a single CI runner opening parallel connections can trip it on its own.

The refused-vs-timeout guide has a longer section on MaxStartups drops during automated deployments if that matches your situation.

Did PerSourcePenalties put your address in the penalty box?

OpenSSH 9.8 (released 2024-07-01) added PerSourcePenalties, enabled by default. The release notes describe it this way: when a client address repeatedly fails authentication, or its behaviour crashes sshd, “sshd will record a penalty of some duration (e.g. 30 seconds) against the client’s address. If this time is above a minimum configurable threshold, then all connections from the client address will be refused (along with any others in the same PerSourceNetBlockSize CIDR range) until the penalty expire.”

The current man page lists the penalty types: authfail, invaliduser, noauth (clients that disconnect without attempting authentication), grace-exceeded, crash and, on newer versions, refuseconnection, plus a min threshold before enforcement and a max cap. Defaults differ between releases, so check yours with sshd -T.

The traps here are shared addresses:

  • An office or VPN behind one NAT address. Somebody’s script with a stale key fails repeatedly, the whole office shares the penalty.
  • CI runners behind a cloud NAT gateway. Same story, and it looks random from inside the pipeline.
  • Health checks and port scanners that open TCP to port 22 and disconnect without authenticating can count as noauth penalties. The man page warns that this timeout “may penalise legitimate scanning tools such as ssh-keyscan(1)”.

Fixes, from least to most invasive:

  • Wait. Penalties expire. If the error disappears after a few minutes and comes back after a burst of failures, this is your cause.
  • Fix the client that keeps failing. A cron job with a revoked key, a monitoring check using password auth, a teammate’s wrong username: those failures are what earns the penalty.
  • Exempt your management ranges with PerSourcePenaltyExemptList, which takes a comma-separated list of addresses and CIDR ranges:

bash

# /etc/ssh/sshd_config
PerSourcePenaltyExemptList 10.20.0.0/16,192.0.2.15

Keep the list short and specific. Exempting 0.0.0.0/0 is the same as turning the protection off.

Run sudo sshd -t after any change, and keep your current session open until a new one works.

Is hosts.deny or another access list rejecting you?

Upstream OpenSSH removed tcpwrappers support in 6.7 (2014), but some distributions kept patching it in. Ubuntu 24.04’s sshd is one of them:

bash

ldd /usr/sbin/sshd | grep libwrap
# libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0

On a build linked against libwrap, /etc/hosts.deny and /etc/hosts.allow still apply. In the lab, a one-line deny rule for the client address produced exactly this error:

yaml

debug1: Connection established.
kex_exchange_identification: read: Connection reset by peer
Connection reset by 127.0.0.1 port 2299

At the default log level, the lab sshd logged nothing about it, so don’t expect a loud line in the journal. Check the files directly:

bash

grep -v '^#' /etc/hosts.deny /etc/hosts.allow | grep -i ssh

The same family includes NAS and appliance block lists (many have their own “auto block after failed logins” setting in the web UI) and tools that edit these files for you. Tools like fail2ban that ban with firewall rules usually block the SYN instead, which you’d see as refused or timed out rather than this error.

Did an OpenSSH upgrade leave a stale sshd running?

OpenSSH 9.8 also split the server into a listener binary, sshd, and a per-session binary, sshd-session. When a package upgrade replaces the binaries on disk while the old listener keeps running, the old process can fail to start sessions with the new files.

Arch Linux packagers documented exactly this after upgrading to 9.8p1: sshd logged sshd: -R not supported here, and the client saw kex_exchange_identification: read: Connection reset by peer until sshd was restarted. FreeBSD users hit a similar stale-daemon problem after the 13.1 upgrade.

The fix is a restart, but the order matters on a remote machine:

  • Keep the session you upgraded from open.
  • Run sudo sshd -t to check the config parses with the new binary.
  • Restart: sudo systemctl restart ssh (Debian/Ubuntu) or sudo systemctl restart sshd (most others).
  • Open a new connection from a second terminal before closing the first.

If you already closed the session, you need console access: your cloud provider’s serial or web console, IPMI, or physical access.

Is something other than sshd answering on that port?

If nc showed no banner, check what owns the port. A lot of things accept TCP and then close it:

  • A container or VM port mapping whose target isn’t running sshd. The host’s proxy accepts, finds nothing behind it, and closes.
  • A load balancer or TCP proxy with no healthy backend.
  • An SSH tunnel or port forward pointing at a closed port on the far side.
  • A different service entirely, such as an HTTP server on a custom port you thought was SSH.

In the lab, the fake “accept and close” service gave kex_exchange_identification: read: Connection reset by peer, a service that sent a TCP reset after accepting gave the same, and an HTTP service gave the banner line 0: HTTP/1.1 400 Bad Request lines in verbose mode before closing.

On the server, ss -tlnp shows which process owns the port. If it isn’t sshd, you have found the problem. If it is a proxy, follow it to its backend and check that sshd is running there.

Corporate networks and Git hosts

Some networks pass port 22 to an intercepting proxy or security appliance that resets SSH it doesn’t like. The test is the same: try another network. For GitHub specifically, its docs describe SSH over port 443 for networks that block 22:

bash

ssh -T -p 443 [email protected]

If that works, GitHub documents this ~/.ssh/config entry to make it permanent:

~/.ssh/config

Host github.com
    Hostname ssh.github.com
    Port 443
    User git

The first connection asks you to confirm the host key for [ssh.github.com]:443. Compare it against GitHub’s published fingerprints before answering yes; our guide to host key verification explains why that prompt matters.

What about “Connection timed out during banner exchange”?

This is the quiet cousin of the same failure: TCP connected, but nothing sent a banner before your ConnectTimeout ran out. The lab client printed:

bash

Connection timed out during banner exchange
Connection to 127.0.0.1 port 2303 timed out

Causes overlap with the list above, with a different symptom: an sshd so overloaded it can’t fork, a service that waits for the client to speak first, or a middlebox holding the connection open. The diagnosis is the same nc test; if it hangs, check the server’s load and what owns the port.

A quick checklist

  • ssh -v shows Connection established, then the kex error: TCP is fine, look at the server or whatever answers.
  • nc -w 5 host 22 prints no banner: not sshd, or sshd refusing you.
  • Works from another network: your address is being refused (penalties, access list, ban tool, corporate proxy).
  • Fails for everyone after an upgrade: restart sshd, from a session you still have open.
  • Fails randomly under load or during deploys: MaxStartups.
  • Never: a wrong key or password. Authentication hasn’t started yet.

Where does termique fit?

termique won’t fix a server that drops connections before the banner; no SSH client can. Two parts of it help with the diagnosis, though.

If a host has the termique monitoring agent installed, the agent reports CPU, memory and disk to your account every 30 seconds, separately from SSH, and you can set an alert for when the host stops reporting. When SSH fails with this error but the agent is still reporting, the machine is up and the problem is sshd or the path to port 22, not a dead server. Hosts whose agent stopped reporting show up under Needs attention in the host list.

termique also lets you pick a jump host per server under Connect via, so you can keep port 22 closed to the internet and reach servers through a bastion. That cuts the bot traffic that eats MaxStartups slots and earns penalties.

Credentials, including private keys, sync between your devices end-to-end encrypted; host entries, groups and snippets sync as plaintext metadata. termique is a free, native ssh manager we build, with end-to-end encrypted credentials. You can download it here.

FAQ

Is kex_exchange_identification a problem with my SSH key?

No. The error happens before key exchange and before authentication, so your key, password and authorized_keys haven’t been looked at yet. Fix the connection first; key errors look like Permission denied (publickey).

Why do I get “kex_exchange_identification: read: Connection reset by peer” with GitHub?

GitHub’s servers are rarely the cause. It is usually the network between you and GitHub: a proxy, VPN or firewall interfering with port 22. Test with ssh -T -p 443 [email protected]; if that works, use the port 443 config shown above.

Why does it work from one network but not another?

Because the server, or something in front of it, is reacting to your source address: a PerSourcePenalties penalty, a hosts.deny entry, a NAS block list, or a corporate proxy on your side. Shared NAT addresses make one person’s failures everyone’s problem.

Will restarting sshd fix it?

For the stale-daemon case after an upgrade, yes. For MaxStartups exhaustion it helps only until the slots fill up again. For penalties and access lists, fix whatever triggers them instead. Always run sshd -t first and keep a working session open.

What does “Connection closed by remote host” without kex_exchange_identification mean?

If it appears right after connecting, it is very likely the same failure. In the lab, the 9.6 client printed only Connection closed by <host> port <port> for a clean close at the default log level; ssh -v added the kex_exchange_identification line.

For the hardening side (key-only login, limiting exposure, access policy), see our complete guide to SSH security.