Sharing a Session
This chapter delivers a second person in your session: another terminal — across the room or across the network — showing the same window, live, able to watch and able to type. It is the teaching and pair-debugging chapter, and it starts with the rule that makes the rest safe to use.
The rule for sharing
An attached client has your keyboard. Anyone attached to your session sees everything in it and can type anything into it — commands run as you, with your permissions, in a shell you may have left logged into other things. So: share sessions the way you would hand over your actual keyboard. With a colleague you are debugging with, yes. As a way to "let someone look at the server", no — that is an account they should have, not a seat in yours. Chapter 1's one rule has a domestic cousin, and this is it.
Two terminals, one session: -x
The simple case needs no configuration at all. You are attached to a session in one terminal. In a second terminal — another window on your desk, a second SSH login (chapter 10) — run:
screen -x work
where -r work would refuse or demand
you detach the first client, -x
simply joins it. This is multi-display
mode: two clients, one session, both
live. Type in either and the text
appears in both; run a command in one
and its output scrolls in the other.
Windows, scrollback and the programs
are the session's, shared exactly.
Geometry is per client — regions
(chapter 6) belong to the display that
made them — except that the window's
size follows the smallest attached
terminal, so a small laptop screen can
shrink a big monitor's window while
both are attached.
The lab ran this for real, with two
scripted clients (transcript
screen-lab/transcripts/t06-sharing.txt).
Client A attached with -x and typed;
client B attached with -x and saw
A's line already on the screen before
typing its own. The session's window,
afterwards:
lab@htch-runtime:~$ echo typed-by-client-A
typed-by-client-A
lab@htch-runtime:~$ echo typed-by-client-B
typed-by-client-B
Two authors, one shell, no taking
turns handing it over. While both were
attached, screen -ls from outside
showed the session as simply
(Attached) — the list does not count
clients for you.
Pair work, in practice
The pattern this enables, and the one worth learning:
- The driver starts the session and
does the work; the passenger
attaches with
-xand watches the same window. - Either can type. One keyboard at a time is a social rule, not a technical one — both clients' input goes to the same shell, and two people typing at once produces the interleaved nonsense you would expect.
- The passenger can take the wheel by typing, and hand it back by stopping. No ceremony, no screen-share negotiation, no "can you see my screen?" — at terminal speeds it feels like sitting at the same keyboard, because mechanically it is.
For teaching it is better than a recording: the student watches real commands land in a real shell, and can be handed a live prompt at any moment — "you run the next one" — with the teacher watching the keystrokes arrive.
A second user: multiuser mode
Everything above shares within one account. Screen can also admit a different user on the same machine, deliberately, by name:
# inside the session, or with -X from outside:
multiuser on
acladd theirname
after which that user can attach with
screen -x yourname/work — your user
name, a slash, the session name. The
aclchg command trims what a named
user may do, down to watching without
typing; the manual's ACL section is
the full grammar.
The lab describes this route from the
documentation rather than demonstrating
it, and criteria.md says why plainly:
on a stock install the Screen binary's
file permissions are part of how this
door is guarded, and the lab's unpacked
copy does not reproduce that setup, so
the commands are given, not vouched
for. The -x sharing above is
vouched for, and covers the common
case — two people who can both log in
as the session's owner, or one person
at two terminals.
Locking the door behind you
A session left attached on an unattended terminal is an open shell to whoever sits down. Two habits cover it: detach when you walk away (Ctrl-A d), and know Ctrl-A x, which locks the session — the display freezes behind a password prompt (your account password) while the programs inside run on. Unlocking needs the password; there is no override from inside the lock, which is the point, and also why chapter 14 lists a forgotten lock among its symptoms with the outside remedy.
Check
Attach to a session in one terminal,
then screen -x it in a second. Type
in the second; watch the first keep
up. Compare with transcript t06: same
window in both places, both lines in
one shell's history, and one
(Attached) in the list outside.