Back to all posts
ScreenSSHTechnologyUbuntu

SSH and Screen – Useful Tips

SathishMay 4, 2011
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.

bash
apt-get install screen

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

bash
screen

To Start a new screen session with user defined session name

bash
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,

bash
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,

bash
screen -ls

Assume we have two screen Sessions as below, which could be viewed from screen -ls command,

text
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,

bash
screen -r 2477.pts-0.server1

To close the session,

bash
exit
0claps
Share this post

Comments

Protected by reCAPTCHA v3

No comments yet. Be the first to comment.