SSH connection fails with "Too many authentication failures" error
Last updated: June 29, 2026
If you're experiencing SSH connection failures when trying to connect to a running Codemagic build instance, you may encounter an error like:
Received disconnect from [IP] port [PORT]:2: Too many authentication failures
Cause
This error occurs when your SSH agent has multiple SSH keys loaded, and SSH tries all of them before reaching the correct one. SSH servers typically limit the number of authentication attempts, causing the connection to fail.
Solution
To resolve this issue, modify the SSH command in the connection script to use only the specific key provided by Codemagic. Add the -o "IdentitiesOnly=yes" option to your SSH command:
ssh -o "StrictHostKeyChecking no" -o "IdentitiesOnly=yes" -t -i $ssh_key -p [PORT] builder@[IP_ADDRESS] < /dev/tty
The IdentitiesOnly=yes option tells SSH to only use the identity files specified with the -i flag and ignore any keys loaded in your SSH agent.
Alternative Solutions
If modifying the SSH command doesn't work for you, try these alternatives:
Stop the current build and start a new one, then try connecting again
Clear your SSH agent keys temporarily with
ssh-add -Dbefore connecting