Archive for March 23rd, 2014

Using ‘screen’ for multiple SSH sessions from a remote computer

Sunday, March 23rd, 2014

1. Log in to the remote server.
2. Type 'screen'. The virtual screen #0 will be opened. We’ll use it as a starting point for creating other screens.
3. Type 'screen -t server1'. This command will open one more virtual screen with title ‘server1’, we will use it for entering the server1, for example ‘ssh server1’.
4. Press Control-a and then ” (double inverted commas)
This command will list all your virtual screens. You may select any of them moving with up/down arrows and then pressing enter. Enter the screen #0.
5. From screen #0 we can create one more screen, for example 'screen -t server2'.
6. Jumping from one screen to some other can be done with Ctrl-a and then ” or Ctrl-a and the number of screen. In our case – 0, 1 and 2.
7. You may close any screen with Ctrl-D or 'exit', like usual.

Another scenario:

1. screen -S 1st_session_name to start screen with some session name.
2. Ctrl-a d to detach from session.
3. screen -ls to list all sessions and their pids.
4. screen -r %pid% to reconnect to a session with %pid%.