How-to avoid ssh prompt for password

Sometimes, we don’t want to use password authentication when using ssh. For example, I wrapped ssh in my script. I want to it always uses key authentication. If there is no key setup, just exit.

I googled it. Most of them are given the option “PasswordAuthentication no”. But in my test, it didn’t work somehow (probably add it the ssh config file will work, but that’s not what I want):

 ssh dbox036 date
The authenticity of host 'dbox036(10.1.1.1)' can't be established.
RSA key fingerprint is 50:ca:af:6c:27:b3:8d:74:e7:27:97:46:36:43:67:78.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'dbox036,10.1.1.1' (RSA) to the list of known hosts.
oracle@dbox036's password: 
Permission denied, please try again.
oracle@dbox036's password: 

I read ssh document and found parameter “NumberOfPasswordPrompts” can be used:

$ ssh  -o "NumberOfPasswordPrompts 0" dbox036
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

If you want to avoid the host key checking, add option “StrictHostKeyChecking no”

$ ssh -o "StrictHostKeyChecking no" -o "NumberOfPasswordPrompts 0" dbox036
Warning: Permanently added 'dbox036,10.1.1.1' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

If you want to avoid the “Warning” message, add option “LogLevel=quiet”, you will get nothing if it didn’t work

$ ssh -o "StrictHostKeyChecking no" -o "NumberOfPasswordPrompts 0"  -o LogLevel=quiet dbox039 date
$
Advertisements

About Alex Zeng
I would be very happy if this blog can help you. I appreciate every honest comments. Please forgive me if I'm too busy to reply your comments in time.

One Response to How-to avoid ssh prompt for password

  1. Pingback: Fix Git Permission Denied (publickey Gssapi-keyex Gssapi-with-mic Password) Windows XP, Vista, 7, 8 [Solved]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: