HowTo Share A Terminal Session Using Screen

From NST Wiki
Revision as of 13:39, 4 September 2011 by Paul Blankenbaker (talk | contribs) (Attaching To A Existing Screen)
Jump to navigationJump to search

The screen command can be 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).

Setting Up A Shared Screen

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:

[pkb@rice ~]$ screen -r 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.

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 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
  • Enable multi-user mode
  • Add the desired user(s)
[pkb@rice ~]$ screen -r shared
[pkb@rice tmp]$ Ctrl-a :multiuser Ctrl-a :acladd megan

The other user should then be able to connect to the shared screen using the following command:


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 :multiuser 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.