Wednesday, 14 March 2012

How to use screen in mulit user mode in linux?

Linux screen command is one of the most used command in my life. Not only it is very useful but also it is very versatile. Screen is mainly used to run another terminal inside our normal linux terminal.

For example, you are connecting to your remote computer over ssh and want to run a script which will take more than 1 hour to execute. Normal cases there are chances that your remote connection over ssh might get disconnected. If so you need to start the whole process again as once the remote connection get disconnected, the running process will also stops.

In this case, screen is very useful as we can create screen inside our current terminal in the remote server and start the script over there in the screen. So even after your remote ssh connection get disconnected, the script will run without any problem in the screen.

This is very convenient as you can start once process in screen in remote server from one computer and continue work on the same screen in the remote server from another computer over ssh. Now let's check some useful screen commands.

1. screen -S screenname 

eg: screen -S backup

This case we are naming the screen as 'backup' and we are going to run the backup script inside that screen. You can name anything you like for your screen. 

2. Ctrl+a -->> This is the screen's hot key. ie, whatever we starts with Ctrl+A and another key will invoke a screen command and can be used to perform different operation

3. Ctrl+a+d -->> This will detach your screen session. That means if you are running your backup script in the screen and press this key combination, it will simply detach from your screen and give you your normal terminal. You can later re-attach to the same screen and see the progress of your back up process.

4. screen -r screenname

eg: screen -r backup

 This will re-attach you to your screen session name backup

5. screen -ls -->> This command will list your all the available screen's in your terminal.

6. screen -x screenname 

eg: screen -x backup

This will re-attach to your screen name backup. Not only that this is the multi user mode of the screen. That means for example, you are already connected to remote server and running the back up script in the screen name 'backup' and you want your friend too see what is happening inside the screen while you are also there inside the screen. Your friend just need to use screen -x backup after logging in to the remote server. This will be really helpful if you want to teach some of your friend how to run back up process in remote server while you and your friend and in different location or both of you are in different computers.

Thus using this command, we can use screen as a great teaching tool also. 

There are many more different screen commands and tips and tricks but these are my most used screen commands. We will see in depth about screen later. 

UPDATE: More screen tutorials can be found below.

Most useful screen shortcuts and commands in linux

How to directly login to the screen session running on your remote server using ssh

No comments:

Post a Comment