Server Administration & Management

How To Share Linux bash sessions

Sometimes it happens that we must give support to a colleague or a customer on a Linux machine. It’s very difficult to spell all bash command I will use to check which could be the problem, especially by phone. “screen” command is a solution about this problem. First install Screen.

# yum install screen

You should use screen by simply ask to the user you want to assist to type on the console the following command

# screen

So if you can connect to the machine (even with ssh) you should run the following command

# screen -x

to share the same bash session.

September 25, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , | Leave a comment

Screen command

Many times as a Linux sysadmin, you will need to run multiple commands at once. You are probably doing this by opening multiple ssh sessions but there is a better way to do it ! Also as a sysadmin you probably had to run a command or script that is taking hours to finish like a rsync. This usually requires you to keep the ssh session open as if you close it the command or script will also be closed. If you ever faced any of those problems then it’s probably time to learn about the screen command.

Screen – makes it possible to run multiple full-screen pseudo-terminals from one real terminal, and lets you manipulate and save your screen input and output, copy and paste between windows.

First of all make sure that you have screen installed. If you don’t you can install it using yum, apt-get or any other package manager that you might have on your server.

# yum install screen

Now type in:

# screen

This will start a new screen for you. You could also name you screen using the -S option. Something like:

# screen -S 1

In this case I named the screen “1?.

The screen will look like any other ssh window. You can now type in your command that you want to run.

If you want to detach from the screen and still keep the command running you can do this by pressing:

Ctrl-a d (that is press Ctrl-a, release and press d)

Detaching a screen

To detach a screen, press ctrl+a release and then d. then you can just exit from your ssh shell. When you want to recover the jobs running under that screen just re-attach it.

Attaching to sessions again

First review the list of screen sessions you have running.

# screen -ls

There is a screen on:
3946.pts-0.arch (Dettached)
1 Socket in /tmp/screens/S-ggarron.

To resume the session run:

# screen -r 3946.pts-0.arch

If you want to reatach to a screen you simply type in:

# screen -r

Other options that you have when you are in a screen are:

1. To create a new screen:

Ctrl-a c

2. To switch between screens:

Ctrl-a n

3. And many others.

January 30, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , | 1 Comment