views:

18

answers:

2

Hello, I would test via a python script whether a passwordless ssh login has been setup or not. If i run the normal ssh command then it will wait to accept the password for some amount of time. Is there a way where the ssh command should return an error as soon as ssh asks for a password.

Is it possible to achieve this?

A: 

paramiko will raise an AuthenticationException if you don't pass a password to the SSHClient's .connect() method and a working key cannot be found.

Wooble
+2  A: 

The ssh command accepts quite a large set of options, so assuming that your Python code is calling shell commands do the following :

ssh -oNumberOfPasswordPrompts=0 <host> "echo hello"

This will instantly fail if the keys have not been setup, and instantly complete if they have, which is the reason for the command being passed to the host. This gives you a simple test.

Amoss