Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python打开交互式ssh shell时出错_Python_Ssh_Subprocess_Popen_Fabric - Fatal编程技术网

从python打开交互式ssh shell时出错

从python打开交互式ssh shell时出错,python,ssh,subprocess,popen,fabric,Python,Ssh,Subprocess,Popen,Fabric,我试图通过fabric打开一个交互式ssh shell 要求: 在远程连接字符串中使用结构主机 在当前终端中打开完全交互式外壳 在osx和ubuntu上工作 无需在fabric/python和远程服务器之间进行数据传输。所以结构任务可以在后台结束。 到目前为止: fabfile.py: def test_ssh(): from subprocess import Popen Popen('ssh user@1.2.3.4 -i "bla.pem"', shell=True) 在

我试图通过fabric打开一个交互式ssh shell

要求:

在远程连接字符串中使用结构主机 在当前终端中打开完全交互式外壳 在osx和ubuntu上工作 无需在fabric/python和远程服务器之间进行数据传输。所以结构任务可以在后台结束。 到目前为止:

fabfile.py:

def test_ssh():
    from subprocess import Popen
    Popen('ssh user@1.2.3.4 -i "bla.pem"', shell=True)
在终端:

localprompt$ fab test_ssh
localprompt$ tcsetattr: Input/output error

[remote ubuntu welcome here]

remoteprompt$ |
然后,如果我尝试在远程提示符上输入命令,它将在本地执行,我将返回到本地提示符。 有人知道解决办法吗


注意:我知道fabrics open_shell,但这对我不起作用,因为标准输出滞后,导致无法使用。

稍微修改一下即可:

def test_ssh():
    from subprocess import call
    call('ssh user@1.2.3.4 -i "bla.pem"', shell=True)
正如对这个问题的回答所表明的,这个错误表明ssh无法连接到stdin/out后台进程


使用call时,fabric任务不会在后台结束,但只要它不干扰我的stdin/out,我就可以这样做

为什么要使用fabric打开ssh shell?为什么不将命令作为fabric任务运行呢?上面的代码根本没有使用fabric。Popen是一个本地命令。我认为在fabric任务中执行它是没有意义的。嗯,通常我通过fabric做一些事情,但有些事情只需要一个交互式shell。我想用fabric来实现这一点,因为现在我有大约20多个sh脚本来连接到我的各种服务器,而让连接字符串保持同步开始让我烦恼。Fabric将是实现这一点的合适工具,因为它已经拥有所有连接字符串。