【发布时间】:2016-03-19 00:52:21
【问题描述】:
我正在尝试创建 ssh 反向隧道。当我在终端上运行以下命令时,效果会更好:
autossh -M 10876 -N -f -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i /root/.ssh/id_rsa -R 6666:localhost:22 root@**.**.**.** -p 2233
但是当我在 python 中使用os.system() 或使用subprocess 运行它时,它不起作用。当我检查进程列表时,进程已创建并运行,与最后一种方法没有区别。(直接在终端中运行)
python 代码:
command ='autossh -M 10876 -N -f -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i /root/.ssh/id_rsa -R 6666:localhost:22 root@**.**.**.** -p 2233'
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, shell=True)
知道有什么问题吗?
【问题讨论】:
标签: python linux terminal subprocess autossh