kex_exchange_identification: Connection reset, closed, or "Not allowed at this time"
Frank Zhang
- 5 minutes read - 2029 wordsTL;DR
TCP was accepted, then the SSH-2.0- identification line did not finish. Match the reset, closed, banner, or banner-timeout text, and read ssh -v before you touch a key or sshd_config.
Match these lines before you change a key, run ssh-keygen -R, or edit MaxStartups. They show up in Terminal on a Mac, and in git, scp, sftp, or a GUI client on that Mac. A Linux OpenSSH client prints the same function name.
kex_exchange_identification: read: Connection reset by peer
kex_exchange_identification: Connection closed by remote host
kex_exchange_identification: banner line 0: Not allowed at this time
Connection timed out during banner exchange
Older clients print ssh_exchange_identification for this same exchange. Current portable master uses kex_exchange_identification. This page does not name the release where the function was renamed. Treat both spellings as this page.
TCP has already been accepted. The two sides did not finish a line of the form SSH-2.0-…. That line is the protocol identification string, also called the banner. Host-key checking has not run. Public-key authentication has not run.
Rerun the same command with ssh -v. If no banner line appears, add another -v. Read the host, the IP, and the port on Connecting to, and read any banner line that arrived. Then follow the branch that matches the remainder.
These commands were not re-run on a Mac or a VPS for this page. The OpenSSH links below are the portable master tree as read on 2026-11-20. macOS ships its own build of OpenSSH. If man or ssh -v on the machine in front of you disagrees, that copy wins.
What this page is for
Match kex_exchange_identification or ssh_exchange_identification with one of the four remainders above. The words after banner line 0: are the peer’s line, minus the line ending. Not allowed at this time is the capitalisation current sshd writes. People often paste it in lower case. ssh, scp, sftp, and git over SSH all use this client exchange.
A second line often follows, with no function name: Connection reset by <id>, Connection closed by <id>, or Connection to <id> timed out. <id> is an address and a port. It is the same failure leaving through sshpkt_fatal. Match either line.
connection reset by peer with none of those prefixes can also happen later in a session. This page is the identification-exchange case.
What the exchange is
In kex.c kex_exchange_identification, as read on 2026-11-20, the client writes SSH-%d.%d-%s…\r\n, then reads the peer a byte at a time. A line whose first four bytes are SSH- is the identification. Earlier lines are pre-banner lines. ssh.h sets SSH_MAX_PRE_BANNER_LINES to 1024 and SSH_MAX_BANNER_LEN to 8192. Each pre-banner line is debug_f("banner line %zu: %s", n, cp). The 1 flag in debug_f (log.h) inserts the function name: kex_exchange_identification: banner line 0: …. Line 0 is the first one.
The name contains kex_. On this tree the failure is still that read, before algorithm negotiation. ssh_login in sshconnect.c runs only after the basic connection exists, and on failure calls sshpkt_fatal(ssh, r, "banner exchange"). packet.c sshpkt_vfatal then prints a line with no function name: Connection closed by %s, Connection to %s timed out on the client, or Connection reset by %s when errno == ECONNRESET.
read: is error_f("read: %.100s", strerror(errno)). On the glibc used while writing this page, strerror(ECONNRESET) is Connection reset by peer. This page did not open Darwin’s errno header. The words on your screen win. send_error writes plaintext only from the server. A client returns immediately.
| Text on screen | Layer | Where to go |
|---|---|---|
ssh: connect to host … port 22: Connection refused, or Operation timed out / Connection timed out on that connect line | connect() refused or unfinished | Connection refused |
kex_exchange_identification / ssh_exchange_identification / banner line / Connection timed out during banner exchange | TCP accepted; identification unfinished | This page |
REMOTE HOST IDENTIFICATION HAS CHANGED / Host key verification failed / missing ED25519 under strict checking | Banner accepted; host key was not | Host key and the known_hosts tool |
Permission denied (publickey) | Offered keys were refused | publickey |
Too many authentication failures | Too many keys on this connection | Too many authentication failures |
WARNING: UNPROTECTED PRIVATE KEY FILE | That private key file was ignored | Unprotected private key |
Bad configuration option: UseKeychain | Which ssh is on PATH | UseKeychain |
A tunnel whose address and port kept changing is the Chinese incident 一次ssh排错经历. That record is a tunnel and a port. The banner exchange on this page is a different failure.
Read ssh -v first
ssh(1), as read on 2026-11-20, says -v prints debugging messages. The maximum is 3. In ssh.c the first -v sets options.log_level = SYSLOG_LEVEL_DEBUG1; further -v flags stop at SYSLOG_LEVEL_DEBUG3. With no -v, log_init gets SYSLOG_LEVEL_INFO when the level is still unset. log.c drops anything above the current level, so ERROR and INFO show by default, and VERBOSE and DEBUG1 do not.
On this tree the client logs to stderr unless -y selects syslog:
kex_exchange_identification: read: …iserror_f(ERROR), visible with no-v.kex_exchange_identification: Connection closed by remote hostisverbose_f(VERBOSE) and needs-v. The follow-upConnection closed by …is still printed.banner lineisdebug_f(DEBUG1).do_logprefixes that level on stderr withdebug1:, so onessh -vprintsdebug1: kex_exchange_identification: banner line 0: Not allowed at this time. If your build, including macOS’s OpenSSH, hides that line, add another-v. This page does not describe Apple’s mapping.
ssh -v user@host
Connecting to HOST [IP] port PORT. is debug(), so here it also has the debug1: prefix. Read the name, the bracketed address, and the port. debug1: Local version string SSH-2.0-… is the client’s own line. debug1: Remote protocol version means the peer’s identification was accepted; keep going to a later row in the table.
ssh(1) -G prints the configuration after Host and Match, then exits, and does not connect. In ssh_config(5), Hostname is the real host and Port defaults to 22.
ssh -G host | grep -iE '^(hostname|port|user) '
A hostname or port that differs from what you typed means the banner came from that target. An empty grep means you read the full ssh -G host output.
Not allowed at this time
That capitalisation is the plaintext in sshd.c drop_connection, as read on 2026-11-20:
const char msg[] = "Not allowed at this time\r\n";
accept has already returned. The function writes those bytes, and the caller closes the socket. Two checks produce the same bytes. PerSourcePenalties: srclimit_penalty_check_allow failed, so that source address is penalised. sshd_config(5) enables penalties by default; the off switch is the keyword no. Leave them on. MaxStartups: too many concurrent unauthenticated connections. should_drop_connection starts at max_startups_begin with probability max_startups_rate/100, and drops every new connection at max_startups. The same branch also applies the per-source cap (srclimit_check_allow) and logs the reason MaxStartups.
The manual’s default is 10:30:100: from 10 unauthenticated connections, refuse with probability 30%; the probability rises linearly; refuse all of them at 100. “full (60)” belongs to the worked example 10:30:60, not to the default. servconf.c fills in 10, 30, and 100 when those numbers are unset. Extra connections wait until one authenticates or its LoginGraceTime expires (default 120 seconds; SSHD_DEFAULT_LOGIN_GRACE_TIME in servconf.h). PerSourceMaxStartups defaults to none. If it is set, the manual uses whichever cap is lower.
The server log format is drop connection #%d from [%s]:%d on [%s]:%d %s. The last field is MaxStartups on that branch. On the penalty branch it is the subreason when set. srclimit.c includes penalty: failed authentication, penalty: exceeded LoginGraceTime, and too many penalised addresses. This page did not collect a live log. A rate-limited stretch also logs %s logging rate-limited: additional %u connections dropped.
If you administer the server, read that log first. Look for what is holding pre-auth slots: scanners, stuck clients, a CI job opening many connections. LoginGraceTime is how long one slot stays occupied. sshd(8) -T writes the effective configuration and exits. This tree spells the lines MaxStartups, PerSourceMaxStartups, PerSourcePenalties, and LoginGraceTime. If your binary changes the case, read what it printed.
sudo sshd -T | grep -iE '^(maxstartups|persourcemaxstartups|persourcepenalties|logingracetime) '
A huge MaxStartups, PerSourcePenalties no, or stopping sshd is not the first change. If you only have the laptop, that sshd_config is not yours to edit. Confirm Connecting to, retry later, or ask the operator to read the drop line. Opening port 22 does not clear a socket that was already accepted.
Reset by peer, or closed by remote host
A short read takes one of two paths. errno == EPIPE logs verbose_f("Connection closed by remote host") and returns SSH_ERR_CONN_CLOSED. Any other short read logs error_f("read: %.100s", strerror(errno)) and returns SSH_ERR_SYSTEM_ERROR. The peer closed or reset before a valid SSH- line, or just after a pre-banner line.
What follows is general guidance. This site has no recorded session of these lines. The port may have accepted TCP for something other than sshd (HTTP, TLS, or any text that does not start with SSH-): read the banner line. A load balancer or firewall may have closed the socket after TCP and before the identification line. The server process may have exited mid-read. drop_connection may have run without this log level printing banner line.
Stay with the port on Connecting to and the banner line from -v. A later read-only probe with no payload is the nc -vz section of the connection refused note. This page does not invent a transcript of that command. fail2ban, a cloud security group, and a vendor appliance come after the banner text is known.
Timed out during banner exchange
When a timeout is in effect and waitrfd returns ETIMEDOUT, kex.c calls error("Connection timed out during banner exchange"), with no function-name prefix, and returns SSH_ERR_CONN_TIMEOUT. The follow-up line is Connection to <id> timed out.
ssh_config(5) ConnectTimeout replaces the system TCP timeout and covers both the TCP connect and the initial handshake. An unset value shows up in ssh -G as connecttimeout none. timeout_connect then blocks in connect() when the timeout is not positive, and the banner ETIMEDOUT path runs only while time remains. during banner exchange means TCP already completed.
Operation timed out or Connection timed out on the ssh: connect to host line is the earlier phase, on the connection refused page. The two timeouts are different failures.
A line that is not SSH-
The peer sent bytes that are not an SSH-x.y-… identification. The client keeps reading pre-banner lines until one starts with SSH-, until it has seen 1024, or until a line is invalid. Longer than 8192 bytes logs banner line too long. A NUL, or a byte between \r and \n, logs banner line contains invalid characters. Both are verbose_f, then SSH_ERR_INVALID_FORMAT. Passing 1024 non-SSH- lines logs No SSH version received in first 1024 lines from server. A line that starts with SSH- but does not match SSH-%d.%d-%[^\n] logs Bad remote protocol version identification. The server-only helper can write Invalid SSH identification string. A client does not.
A middlebox or a VPN appliance can close the socket or send a banner that is not SSH. Fortigate appears in search suggestions for ssh_exchange_identification. This page is not a Fortigate guide.
Where this page stops
The commands were not re-run on a Mac or a VPS for this page, and no session here reproduces this banner failure. man and ssh -v on the machine win. This page states no search volume. A new key, chmod on a private key, ssh-keygen -R, and deleting known_hosts wait until a banner has succeeded, as do an account lock, a GitHub authentication failure, and a host-key change. A MaxStartups in the thousands and PerSourcePenalties no are not the first edit. Windows OpenSSH can print the same function names; this walkthrough is the Unix and macOS ssh. fail2ban, a cloud security group, Cisco, and Fortigate stay as later checks.
Other paths on the site start at Start Here. The Chinese writeup is kex_exchange_identification:Connection reset / closed,或 Not allowed at this time.
If this post helps, you can sponsor the blog. This is voluntary personal support, not a charitable donation.