UserYmY UserYmY - 1 year ago 67
Bash Question

How to run ssh -vvv host through a python script?

I would like to check the authentication method (whether public key or password or both) of a bunch of IP addresses through SSH -vvv host command using a python script that does not require password.

basically I am interested in the below line of the result:

debug1: Authentications that can continue: publickey,password

Here is what I have tried but it does not work since it asks for password.

process = subprocess.Popen("ssh -vvv host", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output,stderr = process.communicate()
status = process.poll()
print output

Can anybody help?

Answer Source

You could try to use

ssh -o KbdInteractiveAuthentication=no -o PasswordAuthentication=no -vvv

That instructs the client not to try keyboard interactive or password authentication, but the server will still send which methods it supports. It may still ask for confirmation if the host is unknown (could be disabled with -o StrictHostKeyChecking=no). Maybe you'll also want to disable other authentication methods listed in the manual.

edit: ssh -o PreferredAuthentications=none should also work