Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
13 years, 9 months ago
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?
Sep 3, 2009 at 10:58
2,271 4 4 gold badges 18 18 silver badges 22 22 bronze badges
For OpenSSH there is BatchMode, which in addition to disabling password prompting, should disable querying for passphrase(s) for keys.
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”.
ssh -oBatchMode=yes -l <user> <host> <dostuff>
Sep 3, 2009 at 12:09
Kjetil Joergensen Kjetil Joergensen
5,984 1 1 gold badge 27 27 silver badges 20 20 bronze badges
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
To disable it for just some hosts, add the following to ~/.ssh/config:
Host host1 host2 host3...
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 restart
Sep 3, 2009 at 11:19
6,743 31 31 silver badges 34 34 bronze badges
If you are using dropbear, just add the "
-s" option to disable password authentication.
Sep 3, 2009 at 11:54
7,395 1 1 gold badge 20 20 silver badges 20 20 bronze badges
On the command line (or
~/.ssh/config) you can set
7,565 16 16 gold badges 55 55 silver badges 74 74 bronze badges
Sep 3, 2009 at 11:39
31.1k 62 62 gold badges 189 189 silver badges 253 253 bronze badges
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.
sftp -o "IdentityFile=<YOUR_IDENTTIY_FILE>" -o "BatchMode=Yes" userName@ftpserver.com <<EOF
mget *.csv $localpath/download
if [[ $exit_code != 0 ]]; then
echo "sftp error, failed to connect to ftp server" >&2
Jun 18, 2020 at 15:55
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only