Ssh Via Python Subprocess.popen: Terminate If Password Requested
I'm using a python script to manage ssh fingerprint problems after a workstation(s) is reimaged. I attempt to connect with ssh, and if I get a any warnings I deal with them. Howeve
Solution 1:
The easy answer is simply to tell ssh
that you don't want to support password authentication at all; you'll still get the messages you want if the host key is changed, but you won't ever have the process hanging waiting for a password to be entered.
cmd = ['ssh',
'-o', 'PasswordAuthentication no', ### <-- THIS LINE HERE'-o', 'StrictHostKeyChecking yes', ### also, never modify known_hosts'-q',
'%s@%s' % (ADMIN_USER, + node),
'exit']
If you did not want to process other prompts, I would suggest setting stdin=subprocess.DEVNULL
(in Python 3) or passing the -n
argument to ssh to prevent stdin from being passed to the process at all.
Post a Comment for "Ssh Via Python Subprocess.popen: Terminate If Password Requested"