Without exiting from the ssh_tunnel, open new terminal

好久不见. 提交于 2019-12-12 01:12:51

问题


I am using Python and wxpython for gui. I am trying to connect ssh tunnel. After connecting to ssh, wants a new terminal to open and have to continue my operation in local machine. How to achieve this?

I tried subprocess, pexpect and paramiko, but all are capable to connect to ssh but not open the new teminal

Below my code is there which I tried with pexpect:

import time
import sys
import pexpect
c = pexpect.spawn("ssh -Y -L xxxx:localhost:xxxx user @ host.com")
time.sleep(0.1)
c.expect("[pP]aasword")
c.sendline("xxxxxx")
time.sleep(0.2)
c.interact()
c.pexpect([user@host.com~]$)
# here after its connects to ssh then command wont be executed
c.sendline("xfce4-terminal")

On 24/04/2013 I am able to open new terminal but what happens is when the new terminal will open controls from gui doesn't go there. Any help?


回答1:


Opening a new local terminal and connecting an existing process in to it is a little complicated. There are at least three approaches:

  1. Open the terminal before you start connecting, and run all the code that tries to establish the connection from within it. This is simplest. The main drawback is that the terminal will appear even if the connection fails, which might be what you want to avoid.

  2. Run the connection attempt with a session of tmux or screen and if you detect that it succeeded then reattach that session in to a new terminal.

  3. Make your Python program provide a pty that the terminal can attach to - your program will need to hang around and pass input and output between the remote connection and the pty.



来源:https://stackoverflow.com/questions/16161343/without-exiting-from-the-ssh-tunnel-open-new-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!