Blog | Admin | Archives | Random | Recent | Thanks

GNU Screen to keep programs running between SSH sessions

There is a very nifty little utility for *nix that I started using again recently. So that I don’t have to relearn it each time, I thought I would write about it. That way, I’ll be more likely to remember, and if I forget, I’ll have myself a handy little reference here at Checksum Arcanius. A wonderful little side effect of all of this is that you get to learn about GNU Screen.

GNU screen is a great utility for those of us whose entire *nix existance is via SSH. Lets say you have a program that you want to persist between sessions of SSH, but its not a daemon and you want full access to the user interface, so detaching it via the & command line operator isn’t a good solution. What do you do? You use Screen. I have a program that fits this description exactly. Naim, an ncurses-based AIM and ICQ client. After installing, to start a Screen session, simply type “screen”. You will be presented with a new command prompt, and apparently nothing changed. But in reality, now you are in screen, and your life just got better. Now start the program you want to persist between SSH sessions. For me, I type “naim”, and Naim loads. I chat a little here and there, then I decide its time to change computers, or reboot, or whatever. But I want to stay online. So I hit “Ctrl-a” (signalling a command to Screen) then “d” for detach. I go back to the original command line. I then exit, or do whatever else I want. Fast forward to my next log in. I SSH back into the machine, and I want to resume where I left off. So I type “screen -r”, and voila, Naim – pristine and just as it was before – appears before my eyes. No one even has to know I was gone. How wonderful is that? It is even possible to have multiple screens running, and switch between them, but I’m not that advanced yet. But hopefully this little tidbit hasa whetted your appitite to try out the wonderful little utility known as Screen.

2 Responses to “GNU Screen to keep programs running between SSH sessions”

  1. nordsieck Says:

    It gets even better than that… a few days ago (at Linuxfest Northwest) I watched a person chat with another person on the command line (two people on the same “screen”) as one of the two was installing Gentoo for the first time. Very cool.

  2. Matt Westervelt Says:

    If you want to create new screens:

    ctrl-a, c (for create)
    ctrl-a, n (next screen)
    ctrl-a, p (previous screen)


    I usually log in with ‘screen -R -D’ this makes sure that when re-attaching it detaches the old tty.

    If you want to attach to an existing screen, type ‘screen -x’

Leave a Reply