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:
Start the shell somewhere (e.g. in VNC):
screen -S myshell
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
screen bash(or whichever other shell is your preference) and thenscreen -xin some other unrelated shell to connect to the screen you created. – Adam Zalcman Aug 17 '12 at 22:52