Start interactive SSH session from Python script
11,733
I get an interactive terminal if I use os.system('ssh [...]')
Comments
-
sholsapp almost 2 years
I'd like to start an interactive SSH terminal from a Python script without using modules like pexpect or paramiko - I want to stick with what CentOS pre-installed Python provides me (to ease compatibility and deployment issues).
I can run commands fine using the subprocess module, but cannot get an interactive terminal. In Perl, I would just use backticks to achieve this, but am looking for the pythonic way of doing this.
Can someone point me in the right direction?
UPDATE - based on @leoluk's answer, I used the instructions from docs.python.org to come up with:
subprocess.call("ssh ...", shell=True)
-
sholsapp over 13 yearsUsing the instructions to convert os.system to Popen, I was able to make it work.
-
snim2 about 11 yearsThe OP did say s/he didn't want to use pexpect!
-
mart1n about 8 years@sholsapp Can you please share your solution using Popen? Thank you!
-
sholsapp about 8 years@mart1n I've updated the question to use the code that I came up with based on the docs.python.org/2/library/subprocess.html#replacing-os-system instructions for replacing
os.system
.