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 hit Ctrl + 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!
Using it under Windows
A friend once told me about a X Server you can install on Windows that, along with PuTTY (a.k.a. the stuff that makes your Windows useful), can be used to make your terminal windows pop as if you were running Linux! (why aren’t you, by the way? 😉 )
The name of the program is Xming, and that’s all you should need. He gave me the instructions back then, but it’s been a while, so I found this (30sec tutorial with screenshots) and this (text-only, with some troubleshooting info) on Google, tested it, and it worked nicely. A bit slower than on Linux (and the terminal looked pretty ugly – maybe I needed to install the fonts package), but worked.
Quick note, although it is out of the scope of this post: you could set up some shortcuts on the system tray icon for applications you launch regularly, like this. I haven’t tried it, and it is up to you to learn how. In case you feel like writing a nice tutorial or something, I’d be happy to post it here.
Ubuntu Troubleshooting
I was perfectly able to use the above method to connect to the Fedora machine where I work, but couldn’t do the same to my home Ubuntu, where the X applications never ran. I googled around, and found this blog post that might be useful for people running Ubuntu Server. However, that is not my case, but the interesting part for me was this link on the blog post indicating the necessary configs on /etc/ssh/ssh_config
(note it is not the daemon config – not sure why!) which were turned off for me. After that, everything worked perfectly.
On the same blog, there was also this tip for speeding up X11 forwarding, which could be useful eventually.
Wrapping up
Hope you liked it. In case you were wondering, yes, this was what got my friend so excited that made me go ahead and create this blog. Took me a while because I wanted to make it all nicely detailed. So if you get all excited too, I’d love to hear about it on the comments! 😉
May 23, 2009 at 10:41 am
emm. really like it ))
March 11, 2010 at 5:40 pm
What about cases when gnome-terminal isn’t installed on the remote computer?
March 13, 2010 at 12:39 pm
Well, I do not have a solution for these cases yet. If you come up with a solution, please share 🙂
September 1, 2011 at 9:53 am
Maybe this could help you http://www.cyberciti.biz/tips/linux-screen-command-howto.html
You still need to install ‘screen’ in the remote computer, but at least you don’t need X11
Regards
March 15, 2013 at 12:38 am
I want to marry you I love you. AWESOME
April 29, 2013 at 11:43 am
[…] https://idnotfound.wordpress.com/2008/01/14/multiple-terminals-in-a-single-ssh-session/ […]
March 12, 2014 at 12:24 pm
Yeah, but, what if there’s no X server on the remote machine (like a web server)?
Then you use gnu screen.