Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if passwordless access has been setup

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?

like image 684
Cheezo Avatar asked Sep 30 '10 12:09

Cheezo


People also ask

What is Passwordless login in Linux?

SSH passwordless login is an SSH authentication method that employs a pair of public and private keys for asymmetric encryption. The public key resides on the server, and only a client that presents the private key can connect.


1 Answers

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.

like image 57
Andrew Avatar answered Sep 24 '22 14:09

Andrew