I've got a script that SSHes 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?
For OpenSSH there is BatchMode, which in addition to disabling password prompting, should disable querying for passphrase(s) for keys.
Sample usage:
To disable password authentication for the current ssh connection attempt, pass this option on the command line:
To disable password authentication for all future connections to any host add the following to your
~/.ssh/config
:To disable it for just some hosts, add the following to ~/.ssh/config:
The options above apply to out-going ssh connections, i.e. where you're trying to connect to a remote ssh server.
To disable password authentication on an ssh server (i.e. applies to all incoming ssh connections), add
PasswordAuthentication no
to/etc/ssh/sshd_config
and restartsshd
.If you are using dropbear, just add the "
-s
" option to disable password authentication.On the command line (or
~/.ssh/config
) you can setPreferredAuthentications
.Here is a sample sftp bash script snippet. I am using "-o BatchMode=Yes" to disable the password prompt in case of failure. And check the frp return code to check if the ftp connection failed.