Monday, September 23, 2013

Screen Tips for Linux

Using Screen on Linux

These are general notes for using screen on Linux (Ubuntu in my case). For now this will be a working copy and refine as I go!

Why Screen?

Mostly because if you lose your terminal ssh session, you will probably have lost all work you are working on (ie. compile, unsaved file, etc). Screen is a process that runs that hosts your applications running and allows you to re-attach later on. Of course this is a super simplified explanation but one of the most important reasons one would use screen. 

 Installing Screen

For Ubuntu
> sudo apt-get install screen

(For the most part now screen comes with the standard Linux install so you won't need to install it)

Standard Scenario

Local Machine --------- (Network) ------------------ Remote Machine

1. SSH into the remote machine
> ssh <user>@<ip address>

2. Once you have successfully connected start screen
> screen

3. If you are ever disconnected, no worries! Just SSH back to your remote machine and attach to your session

> screen -ls
> screen -r  <session ID>

If you need to force you way back into your session, try the following

> screen -dRR <session ID> 

Using Screen

Starting screen you type in:
> screen

Lists the current open sessions
> screen -ls

Re-attach to a open session
> screen -r <session>

Commands 

Some basic commands below:
Ctrl-A c (create new window)
Ctrl-A n (next window)
Ctrl-A p (previous window)
Ctrl-A d (detach window)
Ctrl-A k (kill window)


Enhancements

You can customize screen using the .screenrc file which you drop into your home folder (ie. /home/<user>)

The links at here provide a good customization of screen that allows you to have "tabs" within your screen session.

If you want to get out see my links below. To get it download it

> wget http://quenenni.domainepublic.net/screenrc.txt

Drop into your home folder and rename to .screenrc

> cd ~
> mv screenrc.txt .screen

Tips

Try not using minicom and screen together. They use common control keys. You can still use it but its annoying sometimes when screen intercepts commands you intended to go to minicom.

Links Used

Good Guide(s) to Screen