Skip to content

/codes/ssh-protocol/ssh-disconnect-reason-codes

SSH disconnect reason codes: "Received disconnect from HOST port 22:2" explained

The commands on this page have not been executed by our verification runner yet.updated
tool
SSH protocol
versions
SSH-2 (RFC 4253, RFC 4250)
os
any

When an SSH connection is closed with an SSH_MSG_DISCONNECT message, it carries a numeric reason code and a text description. OpenSSH prints both: in Received disconnect from 203.0.113.5 port 22:2: Too many authentication failures, 2 is the reason code (SSH_DISCONNECT_PROTOCOL_ERROR) and the rest is the text the other side sent. The code is often generic; the text, and the server's log, say what really happened.

Reason codes (RFC 4253, section 11.1)

CodeNameTypical situation
1SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECTThe server refuses this client address (access rules, fail2ban-style blocks in some servers)
2SSH_DISCONNECT_PROTOCOL_ERRORUsed by OpenSSH for many refusals, including "Too many authentication failures"
3SSH_DISCONNECT_KEY_EXCHANGE_FAILEDKey exchange could not complete
4SSH_DISCONNECT_RESERVEDReserved, not used
5SSH_DISCONNECT_MAC_ERRORA packet failed integrity checking (corruption, a broken middlebox)
6SSH_DISCONNECT_COMPRESSION_ERRORDecompression failed
7SSH_DISCONNECT_SERVICE_NOT_AVAILABLEThe requested service (ssh-userauth, ssh-connection) is not offered
8SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTEDThe peer speaks an unsupported protocol version (SSH-1)
9SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLEThe host key could not be verified
10SSH_DISCONNECT_CONNECTION_LOSTThe connection was lost
11SSH_DISCONNECT_BY_APPLICATIONNormal close: the user logged out, or the server closed an idle session
12SSH_DISCONNECT_TOO_MANY_CONNECTIONSConnection limit reached on the server
13SSH_DISCONNECT_AUTH_CANCELLED_BY_USERThe user cancelled authentication
14SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLEAll authentication methods failed
15SSH_DISCONNECT_ILLEGAL_USER_NAMEThe user name is not acceptable

Codes 0xFE000000 to 0xFFFFFFFF are reserved for private use; IANA keeps the registry of assigned values.

Common messages

  • Received disconnect from HOST port 22:2: Too many authentication failures: the client tried more keys than the server's MaxAuthTries (default 6) allows, usually because an SSH agent holds many keys. Pick the key explicitly with -i ~/.ssh/key -o IdentitiesOnly=yes, or set IdentitiesOnly yes for the host in ~/.ssh/config.
  • Received disconnect from HOST port 22:11: ...: a normal, application-level close. If it happens right after login, check the server's log for a forced command, a Match block or a shell that exits.

Find the real cause

bash
ssh -v user@host                      # client side: which keys were offered, where it stopped
sudo journalctl -u ssh -u sshd -n 50   # server side on systemd distributions
sudo tail -n 50 /var/log/auth.log      # Debian and Ubuntu without journald

The server log contains the reason in plain words (for example maximum authentication attempts exceeded), which the code alone does not show.

Sources