Skip to content
 

A screen/shell server is awesome!

GNU screen is not a new tool and while I’ve known about it for a long time, I’ve never had a use for it. What is the point of having multiplexed terminals when I can simply launch more (under Ubuntu)? When I’m in Windows, I can just launch more SSH connections. While having more screens does make organization of many sessions orderly, I prefer a larger screen and the ability to watch several different sessions at once. So while it might not be useful as just a multiplexer, it turns out GNU Screen is great when you have a dedicated server (a term I am using loosely, basically I mean any machine that’s online 24/7) from which to start AND a decent number of machines to connect to.

My use of GNU Screen is as follows: I have a dedicated screen server inside the company intranet from which I connect (SSH) to all the other servers (which is only 6 at this point in time). I also SSH out to two mail servers run by the operations team. Lastly I have 2 SSH connections outgoing to my personal servers (including the one that runs this site).

Why a dedicated server? Well, that’s easy. The real power in screen is the ability to detach and reattach. If you shut down/crash your laptop, the screen session on the server will not be lost (unlike if you did it from your laptop, in which case it would be lost). Additionally, your server will (hopefully) have an always on connection so that the SSH connections will stay connected (theoretically forever). Better yet, you can reconnect to that screen server from anywhere AND you can even force “steal” a session.

If I leave screen running on my laptop at work and find myself needing to work on something on the road, I fire up Better Terminal Emulator Pro on my Xoom tablet and reconnect to the screen/shell server then forcibly steal the session. This saves me a massive amount of effort (because typing on tablet is bad enough, using symbols make it far worse), always allows me to connect, and is much more secure as the servers require SSH keys (which I’m not about to go leaving on a tablet). Once I get home, I can connect again via PuTTY to finish any lingering emergency work.

Using screen is super easy, but I wanted to share a few commands for the uninformed to make it even faster for them to get started:

  • screen — (From CLI) Launch screen
  • screen -r — (From CLI) Reattach a session locally
  • screen -Dr — (From CLI) Detach the session & reattach it locally
  • screen -Dr — (From CLI) List any screen sessions & their status

The following are key combos in screen itself. They always start with Control+A, then another key

  • Ctrl+a a — Creates a new window and switch to it
  • Ctrl+a n — Switch to the next window
  • Ctrl+a p — Switch the previous window
  • Ctrl+a 0…9 — Switch to window # whatever
  • Ctrl+a ” — List all the screen windows and allow you to switch to them
  • Ctrl+a d — Disconnect from screen

This is, of course, by no means an exhaustive list of options. These are the most common commands that I use (as being fairly new to screen), as such you’re likely to need them as well. I’d also like to point out Ryan Lane’s post on shell servers which is what originally inspired me to do the same. He also lists some useful tips for configuring your .screenrc and .bashrc files to make your server just that much easier to use (I love the forces server name titles).

5 Comments

  1. fred says:

    screen -x will also be your best friend. Essentially, think of it as “sharing” instead of stealing.
    Also, another great use of screen is for connecting serial ports to networking gear (yes, you can give ttyS0 to screen and connect directly to the com port…)
    Also, screen + irssi is an awesome combo, and if you are still using ubuntu, check out byobu which is sort of a fork from screen.

    A bon entendeur,
    Salut!

  2. Eddie says:

    Hi Jon,

    I just discovered this post, its really great! I’m looking to use a tablet (would prefer an iPad but am agnostic and would consider an Android Honeycomb) and set up GNU Screen on an always-on desktop machine so that when I’m out and about I can just bring a tablet with me (I was not aware of GNU Screen and how capable it is with regard to this type of functionality — very well suited for the world we are in now and trending toward with more and more virtual machines and “cloud” stuff). That being said, you also raised a very good point about never carrying SSH keys with you no a tablet (what if your Xoom were stolen or somehow compromised). So then this begs the question, how do you securely get into your your always-running laptop at work from your Xoom (to avail of GNU Screen on your work laptop) from your Xoom?

    Cheers,

    -Eddie

    • Jon says:

      Ok. For for the app:

      Android (as mentioned above) I’ve used Better Terminal Emulator Pro: https://market.android.com/details?id=com.magicandroidapps.bettertermpro&feature=search_result

      On the iPad I’ve used iSSH: http://itunes.apple.com/us/app/issh-ssh-vnc-console/id287765826?mt=8

      Personally I like BTEP on the android a little better simply because I like the way android handles things (hardware key to get ctrl, for example), but iSSH on the iPad is really nice with the transparent keyboard option. Either way you go, there are good options.

      As for security. My suggestion would be this: Create an SSH key for your tablet alone, and use it only to connect to your “screen server”. Set a password on that SSH key, though it doesn’t need to be terribly complicated. You’ll need to verify that said key works with your tablet software (Both support SSH keys, but I dont remember testing them with passwords specifically). If you loose your tablet, the password should keep them out for a little while (They’d probably transfer it off device to be cracked). That should buy you time to connect from another device and scram that key on your server – safe!

  3. Eddie says:

    Jon, thanks for clarifying a suggestion on best practice for using SSH keys with tablets accessing SSH servers! This is the type of conversation we need for the world we’re trending into (highly mobile tablet-ish devices + the need to run multiple SSH sessions into various machines be they physical or virtual)!

    Cheers,

    -Eddie

  4. [...] pmAt my previous company I set myself up a screen server as mentioned in my previous post, “A screen/shell server is awesome!“. There were only a half dozen servers there so if the screen server got rebooted, it [...]

Leave a Reply