Screen SSH Technology Ubuntu

SSH and Screen – Useful Tips

Screen is very useful in running processes despite losing connection to remote server connected with SSH. The detached process could be attached to the terminal and we could continue the work at later stage. This will show you how to use screen utility.

 

On Debian and Ubuntu, you just run the following command to install screen.

apt-get install screen


To Start a new screen session just type the following command in ssh terminal

screen

 

To Start a new screen session with user defined session name
 
screen -S sessionname
 

More commands for screen

Ctrl a c – Creates a new screen session so that you can use more than one screen session at once
Ctrl a n – Switches to the next screen session (if you use more than one)
Ctrl a p – Switches to the previous screen session (if you use more than one)
Ctrl a d – Detaches a screen session (without killing the processes in it – they continue)

Use the following command to close screen session once all the tasks done,

exit

To browse two or more screens,

Ctrl a n / Ctrl a p
 
To view all the detached screen sessions, type the following on the normal SSH terminal,
 
screen -ls
 
Assume we have two screen Sessions as below, which could be viewed from screen -ls command,
 
There are screens on:
        2477.pts-0.server1      (Detached)
        2522.pts-0.server1      (Detached)
2 Sockets in /var/run/screen/S-root.
 
To reconnect to one of the screen session,
 
screen -r 2477.pts-0.server1
 
To close the session,
 
exit
 
Spread the love

3 thoughts on “SSH and Screen – Useful Tips”

  1. Good one ..
    How do we start screen with a name ?
    And can we have threading option when starting a screen ?

Leave a Reply

Your email address will not be published. Required fields are marked *