Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my remote machine, an xterm/shell has been created (by another process). I have full access to that shell through VNC. But really I would like to be using a text mode shell on my local machine.

How can I control the existing remote shell from a local one? I can't create a new shell, that's the point. But I have non-privileged access to the existing remote shell.

share|improve this question
I'm not sure if this is doable in your situation but you could run screen bash (or whichever other shell is your preference) and then screen -x in some other unrelated shell to connect to the screen you created. – Adam Zalcman Aug 17 '12 at 22:52
can you run ssh? if so, and you still really want to use the existing shell, start screen using vnc in that shell, then from ssh you can screen -x as suggested by adam zalcman. – Silverrocker Oct 10 '12 at 18:57

You should start the shells in screen or tmux so they can be easily reattached in a new terminal.

With screen this is done with the following steps:

  1. Start the shell somewhere (e.g. in VNC):

    screen -S myshell

  2. Reattach the shell somewhere else (e.g. a new terminal with SSH):

    screen -x myshell

While the methods above are highly recommended, they are not sufficient for controlling an existing shell. For that you are going to need some additional tricks.

One way to reattach an existing shell (that wasn't launched with screen or tmux) is to use reptyr.

From reptyr's website:

reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don't want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home.

You can simply use the process id (PID) and tell reptyr to reattach it:

reptyr PID
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.