HowTo Share A Terminal Session Using Screen
The screen command can is essentially a terminal based version of VNC and is particularly useful in the following circumstances:
- When you want to leave a terminal session running even after logging out of the system.
- When you want to share a terminal session with another user (sort of like VNC but for the terminal).
Screen Command Sequences
There are many screen commands which you can run. To enter a screen command you use the escape sequence following by the command. For a full list of all of the available commands, run man screen. The following table shows some of the commands which we find most useful:
|Ctrl-a a||Passes a Ctrl-a through to the terminal session running within screen.|
|Ctrl-a d||Detaches from a screen session.|
|Ctrl-a k||Detaches from and kills (terminates) the screen session.|
|Ctrl-a :kill||Also detaches from and kills (terminates) the screen session.|
|Ctrl-a :multiuser on||Make the screen session a multi-user session (so other users can attach).|
|Ctrl-a :acladd USER||Allow the user specified (USER) to connect to a multi-user screen session.|
The following command sequence sets up a shared screen session named shared:
[pkb@rice ~]$ screen -d -m -S shared [pkb@rice ~]$
Listing Your Screen Sessions
The following shows what screen sessions you currently have running:
[pkb@rice ~]$ screen -ls There is a screen on: 8632.shared (Detached) 1 Socket in /var/run/screen/S-pkb. [pkb@rice ~]$
Attaching To A Existing Screen
The following allows you to attach to a existing screen session named shared:
[user@rice ~]$ screen -x shared
Once attached, all of your commands will be done within the screen named shared. To detach yourself from the screen, use the Ctrl-a d command sequence.
If you accidently created more than one screen session with the same name, you will get a error when you try to connect to it similar to the following:
[user@rice ~]$ screen -x shared There are several suitable screens on: 10519.shared (Detached) 10323.shared (Multi, detached) Type "screen [-d] -r [pid.]tty.host" to resume one of them. [user@rice ~]$
In this case, you will need to specify the full screen name (with the leading PID) like so:
[pkb@rice ~]$ screen -x 10519.shared
Killing A Screen Session
To cleanly shutdown a screen session, you can attach to it and then press the Ctrl-a k command sequence.
Sharing A Screen Session With One Account
If you have two people logged into the same account from remote locations, they can easily share a screen session (so what one types the other sees and vice versa). To do this:
- Create a named screen session:
[devel@rice ~]$ screen -d -m -S dbgwindow
- Attach to the screen session in your terminal window
[devel@rice ~]$ screen -x dbgwindow
- Have the other person (logged into the same account) also attach to the screen session
[devel@rice ~]$ screen -x dbgwindow
- At this point both terminal windows should see the same thing.
Sharing A Screen Session With Another User
To share a screen session with another user (for teaching or when there isn't enough bandwidth for VNC), you need to:
- Attach to the screen session which you want to share
[user1@rice ~]$ screen -r shared
- Enable multi-user mode
[user1@rice tmp]$ Ctrl-a :multiuser on
- Add the desired user(s)
[user1@rice tmp]$ Ctrl-a :acladd user2
- Tell the other user to try connecting to the same screen using the following command:
[user2@rice ~]$ screen -x user1/shared
- At this point, you should both be connected to the same screen session and seeing the same thing.
NOTE: Screen sharing with another account requires that the screen command be suid root. If it isn't, the other user will see something like the following when they try to connect to your shared screen session:
[user2@rice ~]$ screen -x user1/shared Must run suid root for multiuser support. [user2@rice ~]$
If you want to enable this multi-user screen sharing feature and you see that error, you will need to kill all of the running screen sessions and then run the following commands:
[user1@rice ~]$ su - Password: [root@rice ~]# chmod u+s $(which screen) [root@rice ~]# chmod 755 /var/run/screen [root@rice ~]# rm -fr /var/run/screen/* [root@rice ~]# exit logout [user1@rice ~]$
I'm guessing that making the screen command suid root is a security issue (otherwise, wouldn't it already have been set this way). So, you may be better off making a third shared account which both users can log into to share a screen session with.