Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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-agent and 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.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

man ssh_config:

 BatchMode
         If set to ``yes'', passphrase/password querying will be disabled.
         This option is useful in scripts and other batch jobs where no
         user is present to supply the password.  The argument must be
         ``yes'' or ``no''.  The default is ``no''.
share|improve this answer
    
Indeed, it did the trick. I did not notice this option in SSH manapage, thanks. –  Zopieux May 18 '13 at 23:04

While the BatchMode answer is certainly the right one, I want to also mention that you can also do: -o PasswordAuthentication=no ; same man page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.