Received disconnect: Too many authentication failures: the client offered too many keys
Frank Zhang
- 5 minutes read - 2068 wordsTL;DR
The server hung up this connection after too many authentication attempts. Count the keys the client offered, then pin IdentitiesOnly yes to the one identity you mean to use.
Match these words before you delete a key or look for a reset. 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 words. What matters is how many identities that one connection offered.
Too many authentication failures
Received disconnect from <host> port 22:2: Too many authentication failures
<host> is whoever answered. The port is the one this connection used. Some programs print only the first line.
This sentence is a per-connection limit. The OpenSSH server counted authentication attempts on this connection and hung up. sshd_config(5) names the cap MaxAuthTries and defaults it to 6. The sentence does not prove the key is bad. By itself it does not prove the account is locked, banned, or due for a reset. The next connection starts the count again. Offer fewer keys, and that next attempt can succeed.
A long list from ssh-agent, or from a password-manager agent, is the usual way the client reaches the cap before the server sees the key you meant. ssh_config(5) already names the client-side response: IdentitiesOnly yes, plus the one IdentityFile, or the one -i file, you mean to use.
The publickey note on this site, dated 2026-11-13, already names this disconnect and that setting: Permission denied (publickey) for git@github.com on a Mac. This page is for when Too many authentication failures is the sentence on screen, often before the right key is offered. If that key does appear under Offering public key and the final sentence is Permission denied (publickey), stop here and use that note. GitHub’s page for the other sentence is Error: Permission denied (publickey). GitHub’s troubleshooting index has no page for this disconnect. That index was checked while writing this page.
No session written up on this site has this disconnect on screen. No agent listing, no Offering public key log, and no server MaxAuthTries were recorded for it. These commands were not re-run on a Mac or a VPS for this page. Flag meanings come from the manuals. Quoted debug strings come from OpenSSH auth.c, auth2.c, auth2-pubkey.c, packet.c, ssh2.h, and sshconnect2.c, as read for this page. Those links are the master tree at that reading. macOS ships its own build. If man on the machine in front of you disagrees, that copy wins.
Thirty seconds
| Text on screen | Read it as | First read-only command |
|---|---|---|
Too many authentication failures, or Received disconnect … Too many authentication failures | This connection used up the server’s authentication-attempt cap. Other keys were often offered first. | ssh-add -l |
The key you meant is in an Offering public key line, and the final sentence is Permission denied (publickey) | The server saw that key and refused it. This page stops. | The publickey note |
Connection refused, REMOTE HOST IDENTIFICATION HAS CHANGED, or Bad configuration option: UseKeychain | Another layer. | The notes under the table |
TCP never reached authentication in the connection refused note. A host-key mismatch is the host key note, and the known_hosts fix command generator fills in that removal. UseKeychain and apple-use-keychain are the UseKeychain note. A tunnel whose address and port kept changing is the Chinese incident 一次ssh排错经历. None of those is this disconnect.
Read the agent and the config first
Nothing here writes ~/.ssh/config, removes a key from the agent, or talks to sshd. Do not put sudo in front of ssh or git. The publickey note already covers that split: sudo reads root’s ~/.ssh.
Replace git@github.com with user@host when the failed command was not GitHub. On GitHub the SSH user is git. A different user belongs to the publickey note.
What the agent is holding
ssh-add -l
ssh-add(1) says -l lists fingerprints of identities currently in the agent. Exit status 2 means it could not contact the agent. A long list is a reason to suspect this error. It is not a count of how many the server will accept.
Leave -d and -D alone for now. The same manual says -d removes listed identities and -D deletes all identities from the agent. Neither deletes key files on disk. Keychain, another agent, or the next ssh-add can load a key again. Clearing the agent is not the first step.
What this client would offer, without connecting
ssh(1) says -G prints the configuration after evaluating Host and Match blocks, then exits. It does not open a connection.
ssh -G git@github.com | grep -iE '^(user|hostname|identityfile|identitiesonly) '
Read identitiesonly and every identityfile line. ssh_config(5) defaults IdentitiesOnly to no. Multiple IdentityFile directives add to the list, unlike most other keywords. If the grep prints nothing, read the full ssh -G output. Keywords are case-insensitive. With IdentitiesOnly left at no, identities in the agent are used as well.
Count the offers
ssh -vT git@github.com
-v prints debugging messages. -T skips a pseudo-terminal. GitHub’s test uses -T because that server has no shell. One -v still shows the offers on a host that does.
In the sshconnect2.c read for this page, Offering public key: is logged when the client already has that public key and is about to send a test. Count those lines before the disconnect. Stay on this page when the key you intended is missing, or shows up only after several others. When that key was offered and the final sentence is Permission denied (publickey), the publickey note covers the rest.
What the 2 is, and what 6 is not
The client format in the packet.c read for this page is Received disconnect from %s port %d:%u: %.400s. The %u is the disconnect reason code. sshpkt_disconnect sends SSH2_DISCONNECT_PROTOCOL_ERROR, which ssh2.h defines as 2, for this class of disconnect. auth_maxtries_exceeded in auth.c disconnects with the reason string Too many authentication failures through that same sender. In port 22:2:, 22 is the port and 2 is that reason code. The 2 is not a count of keys or of failures. The words that select this page are Too many authentication failures. This sender uses reason code 2 for other disconnect texts too.
MaxAuthTries caps failures per connection, default 6. Further failures are logged once the count reaches half that value. In auth2.c, userauth_finish increments the count for a failed method, including a wrong password on that same connection, and calls auth_maxtries_exceeded at the cap.
A rejected public-key query is budgeted first. PubkeyAuthOptions max-pk-ok defaults to 6: queries allowed before they count against MaxAuthTries. A query asks whether the server would accept a key, before a signature. In the auth2-pubkey.c read for this page, a rejected query stays marked already-counted until pk_ok_failures passes max_pubkey_ok, and counts as a failure after that. Count the Offering public key lines in your own log. This page does not assign one key-count to every server. 1Password’s advanced page calls the error a six-key limit and says a seventh key is refused. That is their account of the default. This page did not re-test it, and did not read github.com’s or gitlab.com’s sshd_config.
auth.c logs maximum authentication attempts exceeded for, then the username, or invalid user plus the username. Lines from addresses you did not connect from are other clients failing. A pasted server line ending in [preauth] uses a bracket that is not in the auth.c, packet.c, or log.c text read for this page, so this page does not define it. That wave is a different situation from one client offering its own keys too early. Leave PubkeyAuthentication and StrictHostKeyChecking as they are.
One command that offers less, and writes nothing
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 -vT git@github.com
Replace the filename and the target. ssh(1) -o passes a config keyword. This changes which keys are offered. It does not write ~/.ssh/config.
GitHub shows the same options, with their filename, on a different page, Error: Key already in use: ssh -v -o "IdentitiesOnly=yes" -i ~/.ssh/id_rsa git@github.com. That page is about a key already attached to another account. This page uses the flags only.
-i alone is not enough. Identities from the agent are also used unless IdentitiesOnly is set. If this one-off succeeds and a bare ssh or git still prints the disconnect, the number of keys offered was the cause. If it still ends in Permission denied (publickey) after offering the file you named, the server refused that key. Fingerprints, pasting a .pub, and generating a key stay on the publickey note.
IdentitiesOnly yes without the IdentityFile or -i you intended uses only configured identities, or the default files. The OpenBSD manual read for this page lists ~/.ssh/id_rsa, id_ecdsa, id_ecdsa_sk, id_ed25519, id_ed25519_sk, and id_mldsa44_ed25519. A Mac’s manual may name a shorter list. A key that lives only in the agent, under some other filename, will not be offered.
The lines to keep
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Replace the Host pattern, User, and IdentityFile. scp and sftp to that host use the same client config. The manual also allows IdentityFile to name a public key file, so the matching private key can come from the agent when the private file is not on disk.
Two GitHub accounts, or GitHub and GitLab, need an alias and a remote URL that uses it:
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
The remote becomes git@github.com-work:ORG/REPO.git. github.com-work is a client name. HostName is the real host. The publickey note has the fuller block, including AddKeysToAgent, UseKeychain, key generation, and fingerprints.
IdentitiesOnly yes under Host *, with no per-host IdentityFile, is not the opening recommendation. The client then offers only configured identities or those default filenames. A login that worked only because a non-default key sat in the agent can stop. A global Host * is an optional later default, after you have seen which host needed which file.
ssh-add -d and ssh-add -D stay optional and temporary, after that config is in place. Do not start there. Do not delete ~/.ssh, chmod 777 a key or config or authorized_keys, or rotate every key because this sentence appeared.
When you administer the server
From a console, or a session that already works, read the effective cap. The failing SSH session cannot read the far side.
sudo sshd -T | grep '^maxauthtries '
sshd -T prints the effective config. Raising MaxAuthTries is not the first fix. On a server you do not administer, including github.com, it is the wrong move, and this page did not read that file.
Names from autocomplete
Autocomplete also pairs this sentence with 1Password, vCenter, FinalShell, and “reset”. A password-manager agent that loads many keys can produce the same words. 1Password’s page uses IdentityFile plus IdentitiesOnly yes, and their example points IdentityFile at a downloaded .pub. This page does not walk through that app, and it records no 1Password setup. vCenter and FinalShell are out of scope. “Reset” is not a documented OpenSSH client fix for this sentence.
Where this page stops
- The commands were not re-run on a Mac or a VPS. The manuals and the OpenSSH files linked above are the sources. The
manon the machine wins. - No agent listing and no key count were recorded here. The defaults above are the manual’s, not a log from one Mac.
- github.com’s and gitlab.com’s
MaxAuthTrieswere not read. - A GUI that ignores
~/.ssh/configcan keep offering every agent key after the command-line test succeeds. Point it at the samessh, or at one identity. Those apps are not documented here. - Search volume. This page does not add an external measurement.
Other paths on the site start at Start Here. The Chinese writeup is 出现 Too many authentication failures:先看这次递出了几把钥匙.
If this post helps, you can sponsor the blog. This is voluntary personal support, not a charitable donation.