Using the linux “screen” command to create ssh sessions.

Recently, I had cause to look up this command, which lets you create and manage several shell sessions using a single ssh connection.

This was because one particular task (WAS deployment) was taking a long time and I wanted to kick it off and go home. Now usually you would use the nohup command and drop the process into the background, but for some reason this particular process would stall in the background and sit in the “stopped” state until I foregrounded it again.

Previously I would use vncserver to get ’round this, but security now dictates that vnc software is removed.

This is where screen comes in.

Here is a very brief (for reference) command list available when screen is installed.

screen – starts the screen program
screen -ls – lists running screen sessions
screen -r – reconnect to a running screen session
CTRL-A c – create new screen session
CTRL-A d – detach from current session
CTRL-A n – move to next screen session
CTRL-A p – move to previous screen session
CTRL-A M – monitor session for activity
CTRL-A _ – monitor session for inactivity
CTRL-A k – kill current session
CTRL-A ” – list sessions
CTRL-A ? – key binding list

Want screen collaboration? My collegue Chris pointed out this useful URL

http://ubuntu-tutorials.com/2007/05/17/group-collaboration-with-screen/

If you have created splits in your screen session, you can save the layout so that if the session is detached when re-attached the splits will remain :

CTRL-A : layout save default

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation