The goal is to establish the reverse ssh connection from machine-a to machine-b, so I could ssh connect from machine-b to machine-a after the reverse connection is established.
After importing os
module I go ahead and use os.system
to ssh connect to a remote server using ssh -R 2210:localhost:22 me@80.54.0.107 &
command. Please note that the command line ends with &
character because I want to place the ssh process in the background:
import os
result = os.system("ssh -R 2210:localhost:22 me@80.54.0.107 &")
print("...started ssh connection", result)
But I am getting the error and as a result the ssh connection is not established:
Pseudo-terminal will not be allocated because stdin is not a terminal.
I have tried to run it with subprocess
hoping it will work:
import subprocess
cmd = ["ssh", "-R", "2210:localhost:22", "me@80.54.0.107", "&"]
result = subprocess.Popen(cmd, shell=False)
but it throws another error:
bash: -c: line 0: syntax error near unexpected token `&'
Is there a way to run ssh connection from Python placing it at the background?