http://idnotfound.wordpress.com/2008/01/14/multiple-terminals-in-a-single-ssh-session/
When I sit to work, I am using linux terminals 95% of the time. And I tend to use lots of them. One for vim, another for compiling and testing, another for checking whatever files the program outputs, and so on… If you’re a multiple windows/tabs kind of guy (or gal, why not?) like me, you know what I am talking about!
Ctrl + Shift + N is my favorite shortcut ever on gnome-terminal
, but when I am not physically on the machine but working via SSH, it is not nearly as fun. In fact, it is annoying as hell as it opens a new local terminal, and I have to log in again, go to the path I am interested in, and only then being able to do whatever I want to do (which, sometimes, is pretty quick and I end up closing the terminal, just to regret next time I need it again). Thankfully, I found a nice way to solve this!
Normal Use (under Linux)
Well, a friend of mine reminded me of cool switch that is ssh -X
. What it does is enable X11 forwarding. In other words, it redirects to your local (from your point of view) computer all X/graphical applications you run remotely; that is, if you run, let’s say, gnome-terminal
, it will show a terminal on your computer that is actually running on the remote (again, from your point of view) machine.
Ok, so what do I do with that? How about Ctrl + Shift + N? Cool, uh?
Enough stories, this tip is about opening multiple remote terminals through SSH and only having to log in once. What I do is:
$ ssh -X mylogin@remotemachine gnome-terminal
Password: ...
[Ctrl+Z]
$ bg
$ exit
Ok, that sounded complicated, so I’ll go over it line-by-line:
- The syntax for
ssh
isssh [options] [login@]host [command]
. So what I am doing is connecting with the-X
switch, and runninggnome-terminal
remotely. If you provide a command like this, after the process terminates, the connection is closed. - I enter my password to connect…
- By now, the terminal we ran remotely should pop on your screen. Go back to your local terminal and hitCtrl + Z to pause the
ssh
process. You’ll get a prompt back. - On the prompt, type
bg
, which unpauses the paused process, but runs it on background. - You now close your terminal with
exit
. It is important to useexit
and not clicking on the close button from your window manager, otherwise thessh
process we sent to background will be terminated too, and your remote terminals will disappear. I’m not sure why, but it works like that.
Now you try it… It’s fun, isn’t it? But why, oh why haven’t I just gone with the ssh -X mylogin@remotemachine gnome-terminal &
one-liner? Well, because I couldn’t type my password that way. I know there are ways to allow direct login without password, but I have never fiddled with that that’s covered in anoter post. In case you got direct login working, you could use the one-liner.
If you’re not much into GNOME, things should probably be just the same with other terminals. However, if you’re on a Windows machine… fear not, as you can use this too!