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've got a script that ssh'es several servers using public key authentication. One of the servers has stopped letting the script log in due to a configuration issue, which means that the script gets stuck with a "Password:" prompt, which it obviously cannot answer, so it doesn't even try the rest of the servers in the list.

Is there a way to tell the ssh client not to prompt for a password if key authentication fails, but instead to just report an error connecting and let my script carry on?

share|improve this question
add comment

4 Answers

up vote 39 down vote accepted

For OpenSSH there's also BatchMode which in addition to disabling password prompting should disable querying for passphrase(s) for keys.

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”.

Sample usage:

ssh -oBatchMode=yes -l <user> <host> <dostuff>
share|improve this answer
add comment

add the following to your ~/.ssh/config:

PasswordAuthentication no

and to disable password auth on the server, add the same line to /etc/ssh/sshd_config and restart sshd.

share|improve this answer
4  
if you don't want to disable password auth for all ssh client connections, you can also specify options on the command line. add '-oPasswordAuthentication=no' to your ssh command. –  cas Sep 3 '09 at 11:23
2  
This does not prevent the password prompt. OP's script will still hang. –  Joshua Swink Nov 4 '09 at 20:02
add comment

If you are using dropbear, just add the "-s" option to disable password authentication.

share|improve this answer
1  
+1 for not assuming the client is openssh :-) –  cas Sep 3 '09 at 11:55
add comment

On the command line (or ~/.ssh/config) you can set PreferredAuthentications.

PreferredAuthentications=publickey
share|improve this answer
    
I think that, on the command line, you need to wrap the option in quotes and then pass it to the -o option. –  Craig Walker Sep 11 '09 at 1:20
1  
@CraigWalker You can also pass it as is, i.e. ssh -o PreferredAuthentications=publickey –  Tobias Kienzler Oct 29 '13 at 13:33
add comment

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.