简体   繁体   English

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

[英]Error when opening interactive ssh shell from python

I am trying to open an interactive ssh shell through fabric. 我正在尝试通过结构打开交互式ssh外壳。

Requirements: 要求:

  • Use fabrics hosts in the connection string to remote 使用连接字符串中的结构主机到远程
  • Open fully interactive shell in current terminal 在当前终端中打开完全交互式外壳
  • Works on osx and ubuntu 适用于osx和ubuntu
  • No need for data transfer between fabric/python and remote. 无需在Fabric / python和远程之间进行数据传输。 So fabric task can end in background. 因此结构任务可以在后台结束。

So far: 至今:

fabfile.py: fabfile.py:

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

In terminal: 在终端:

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

[remote ubuntu welcome here]

remoteprompt$ |

Then if I try to input a command on the remote prompt it is executed locally and I drop back to the local prompt. 然后,如果我尝试在远程提示符下输入命令,则该命令将在本地执行,然后退回到本地提示符。 Does anyone know a solution? 有人知道解决方案吗?

Note: I am aware of fabrics open_shell , but this does not work for me since the stdout lags behind, rendering this unusable. 注意:我知道结构open_shell ,但是这对我不起作用,因为标准输出落后,因此无法使用。

A slight modification does the trick: 稍作修改即可达到目的:

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

As the answer to this question suggests the error suggests the error comes from the inability of ssh to connect to the stdin/out of a process in the background. 正如对这个问题的答案所暗示的那样,该错误表明该错误是由于ssh无法在后台连接到标准输入/进程的。

With call the fabric task does not end in the background, but I am fine with that as long as as it is not interfering with my stdin/out. 使用call ,fabric任务不会在后台结束,但是只要它不干扰我的stdin / out,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM