Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A script regularly initiates an SSH connection from one server to another, using SSH keys.

However, once, the keys were briefly overwritten. This caused the SSH client to fall back to asking for a password, which had undesired knock-on effects.

Is it possible to instruct SSH to exit if key-based auth fails, and not fall back to asking for a password?



share|improve this question
up vote 5 down vote accepted

If you don't want to globally disable password authentication on your server you can use the -o "PasswordAuthentication no" option on the ssh command line e.g.

ssh -o "PasswordAuthentication no" YourHost
share|improve this answer
Thanks! This is what I was thinking of. – wodow Dec 2 '10 at 11:01

You can stop password authentication by configuring the ssh daemon. Edit the /etc/ssh/sshd_config file.

#PasswordAuthentication yes

Uncomment and change the above line to "no".

PasswordAuthentication no

Don't forget to restart your ssh daemon!

share|improve this answer

vi /etc/ssh/sshd_config

# To disable tunneled clear text passwords, change to no here!

#PasswordAuthentication yes

#PermitEmptyPasswords no

PasswordAuthentication yes

change yes to no


share|improve this answer

Your Answer


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.