Issue
I would like to capture a ssh password prompt as string in python. For example:
> ssh user@hostname
user@hostname's password:
I need this string 'user@hostname's password:'. A similar question is asked here. I tried to use subprocess and paramiko, but I didn't manage to capture the string. Is there anyway to get it?
Solution
[Solved]
Solved with pexpect. I can read this data from pexpect.spawn. A advantage of pexpect is that, by using interact() method, I can give back control to the interactive user (the human at the keyboard) after program processes the login, which is exactly what I want.
I can fetch the string 'user@hostname's password:' using this method. However, if I want to give the interactive user control after login, it seems complicated.
Answered By - LetsOMG Answer Checked By - Clifford M. (WPSolving Volunteer)