Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top