I am writing a script to cycle through a list a known hostnames so as to find a working SSH server on which I can auth with my SSH key.
The key is already loaded with
ssh-add, so if I connect to a working remote host that knows my key, no passphrase is prompted and I am successfully connected without any interaction.
Thing is, when the remote host does not know my key,
ssh prompts me with the passphrase (it has no chance to succeed because, if it could, it would have already logged me in thanks to
ssh-agent). I would like to prevent this behavior and make
ssh abort when the
ssh-agent auth fails.
I am currently using the following command to bypass most of the interaction but I can not prevent the one I just described:
$ ssh -i ~/.ssh/id_rsa \ -o UserKnownHostsFile=/dev/null \ -o KbdInteractiveAuthentication=no \ -o StrictHostKeyChecking=no \ -o PreferredAuthentications=publickey \ -o ConnectTimeout=1 \ $host -n "whoami"
Thanks for your answers.