March 24th, 2009tips & tricks: using screen to keep your ssh sessions running
screen is a small program that will allow you to keep multiple terminal sessions running and easily switch between them. It also protects you from disconnection, because the screen session doesn’t end when you get disconnected.
to install screen in ubuntu, open a terminal and type the following:
sudo aptitude install screen
now you can start a new screen session by just typing screen at the command line. You’ll be shown some information about screen. press enter, and you’ll be at a normal prompt.
sudo aptitude install screen
to disconnect from ssh, but leave your session open, do the following:
press ctrl+a and then ctrl+d in immediate succession. you will see the message [detached]
to reconnect to an already running session
screen -r
to reconnect to an existing session, or create a new one if none exists
screen -d -r
to create a new window inside of a running screen session
press ctrl+a and then c in immediate succession. you will see a new prompt.
to switch from one screen window to another
press ctrl+a and then ctrl+a in immediate succession.
to list open screen windows
press ctrl+a and then w in immediate succession
there’s lots of other commands, but those are the ones I use the most.