Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I often find myself opening several ssh connections in order to view several log files at a time with tail -f.

This isn't a problem when I'm at home because I use public key encryption for password-less login. However, I will often use computer at my university to do this so I don't have the option of using my private key. It gets annoying to enter my password 4 or 5 times to get several terminal windows.

How can I get multiple terminals over a single connection?

share|improve this question
add comment

8 Answers 8

up vote 36 down vote accepted

Just use GNU screen, it's great as you can start up remote sessions and restore them if your connection drops. It's available as a package for most distributions and may even already be installed on your university system.

The manual will give you all you need to get started, by default all commands are preceeded by Ctrl+A. For example to bring up the onscreen help, just press Ctrl+A then press ?

share|improve this answer
    
I have been a linux admin for several years and use screen many, many times a day. –  borodimer May 1 '09 at 5:34
    
No server is complete without screen. –  Gert M May 1 '09 at 7:03
1  
After using screen for the last few hours I can't believe I lived without it! I've spent 5 years Doing It Wrong. –  epochwolf May 1 '09 at 7:29
add comment

screen allows you to have multiple terminals and more (such as the ability to detach and re-attach to your session).

Some notes to get you going:

Ctrl-a c   create
Ctrl-a d   detach
screen -r  reattach
Ctrl-a a   toggle
Ctrl-a "   list

And some recommended reading:

share|improve this answer
add comment

Take a look at the following two articles on SSH connection sharing:

http://fermiparadox.wordpress.com/2008/06/19/ssh-connection-sharing/
http://protempore.net/~calvins/howto/ssh-connection-sharing/

Basically, do a google search on ssh connection sharing and you'll find a bunch of other articles on it.

share|improve this answer
1  
Interesting. The one issue is that if my internet connection were to drop I would be unable to reconnect without deleting the socket. If I can't connect how do I get into the server to delete the socket? –  epochwolf May 1 '09 at 5:29
    
You don't have to delete the socket on the server, it's only a client-side sharing. So you run `ssh foo' once and it creates the socket on the same machine you ran the ssh foo command on. The server sees multiple logins on separate ttys, so it doesn't know any different to "normal" separate logins. –  David Gardner May 1 '09 at 12:44
add comment

Possibly, you could use X forwarding to open multiple remote xterms on your local desktop.

share|improve this answer
    
Server doesn't have X11 installed. Also, not workable on a windows system that I can't install an X server on. –  epochwolf May 1 '09 at 3:37
    
The Linux server doesn't need to have X11 to run graphical applications that show up on your local desktop. Also, the Cygwin X-Server works great for running things like Firefox from my home Linux box (without X running on my home box) and they show up just fine on my local Windows laptop. –  shapr May 21 '09 at 19:54
add comment

You give no compelling reason why you can't use private keys from the other systems. Generate them per-machine and add the applicable keys to authorized_hosts

Still, use screen.

share|improve this answer
    
Is using a private key on what amounts to a public computer a good idea? Especially considering I didn't put a passphrase on the key? –  epochwolf May 1 '09 at 7:31
1  
You wouldn't use the same key as you use elsewhere - you would generate a new key (with a passphrase) and add its public key to the authorized_keys file on your server. Name it something like "portablekey" and take it out of authorized_keys if you think it might have been compromised. –  Neall May 1 '09 at 11:57
add comment

You may also want to look at byobu. It's an enhanced version of Screen and I believe it's a Ubuntu project. But it comes standard with Ubuntu 9.10 and newer.

I tend to still use Screen though by habit but wanted to mention this newer alternative.

share|improve this answer
add comment

If all you're using it for is tailing several files, you may also be interested in multitail.

share|improve this answer
    
Interesting link. I just mentioned my most common usage. I also need to switch between vim and bash to look up paths for things. –  epochwolf May 1 '09 at 5:27
add comment

One unmentioned screen feature is to "detach" screen and it will keep running whatever commands you have running in that set of screens. Once screen is detached, you can logout and it all keeps chugging away even after logging off. I'll startup screen and then do several c commands to create new 'subscreens'. I can switch between them and start some long running compile or data processing and be assured that my crappy VPN connection won' cause everything to die with it.

After logging off, you can log back in and use 'screen -R' which will re-attach you to your existing screen sessoins.

share|improve this answer
add comment

Your Answer

 
discard

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.