mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Screen.mdwn
1 [Screen][] is a [ncurses][]-based terminal multiplexer.  There are
2 tons of useful things you can do with it, and innumerable blog posts
3 describing them.  I have two common use cases:
4
5 * On my local host when I don't start X Windows, I login to a
6   virtual terminal and run `screen`.  Then I can easily open several
7   windows (e.g. for [[Emacs]], [[Mutt]], [[irssi]], …) without having
8   to log in on another virtual terminal.
9 * On remote hosts when I'm doing anything serious, I start `screen`
10   immediately aftering [[SSH]]-ing into the remote host.  Then if my
11   connection is dropped (or I need to disconnect while I take the
12   train in to work), my remote work is waiting for me to pick up where
13   I left off.
14
15 Treehouse X
16 ===========
17
18 Those are useful things, but they are well covered by others.  A few
19 days ago I though of a cute trick, for increasing security on my local
20 host, which lead me to finally write up a `screen` post.  I call it
21 “treehouse X”.  Here's the problem:
22
23 You don't like waiting for X to start up when a virtual terminal is
24 sufficient for your task at hand, so you've set your box up without a
25 graphical login manager.  However, sometimes you *do* need a graphical
26 interface (e.g. to use fancy characters via [[Xmodmap]] or the
27 [[Compose_key]]), so you fire up X with `startx`, and get on with your
28 life.  But wait!  You have to leave the terminal to do something else
29 (e.g. teach a class, eat dinner, sleep?).  Being a security-concious
30 bloke, you lock your screen with [xlockmore][] (using your [[Fluxbox]]
31 [hotkeys][]).  You leave to complete your task.  While you're gone
32 Mallory sneaks into your lab.  You've locked your X server, so you
33 think you're safe, but Mallory jumps to the virtual terminal from
34 which you started X (using `Ctrl-Alt-F1`, or similar), and kills your
35 `startx` process with `Ctrl-c`.  Now Mallory can do evil things in
36 your name, like adding `export EDITOR=vim` to your `.bashrc`.
37
38 So how do you protect yourself against this attack?  Enter `screen`
39 and treehouse X.  If you run `startx` from within a `screen` session,
40 you can jump back to the virtual terminal yourself, detach from the
41 sesion, and log out of the virtual terminal.  This is equivalent to
42 climing into your treehouse (X) and pulling up your rope ladder
43 (`startx`) behind you, so that you are no longer vulnerable from the
44 ground (the virtual terminal).  For kicks, you can reattach to the
45 screen session from an `xterm`, which leads to a fun chicken-and-egg
46 picture:
47
48 [[!img treehouse-X.png
49   alt="startx → X → Xterm → Screen → startx cycle"
50   caption="startx → X → Xterm → Screen → startx cycle"]]
51
52 Of course the whole situation makes sense when you realize that it's
53 really:
54
55     $ pstree 14542
56     screen───bash───startx───xinit─┬─X
57                                    └─fluxbox───xterm───bash───screen
58
59 where the first `screen` is the server and the second `screen` is the
60 client.
61
62 [screen]: http://www.gnu.org/software/screen/
63 [ncurses]: http://www.gnu.org/software/ncurses/
64 [xlockmore]: http://www.tux.org/~bagleyd/xlockmore.html
65 [hotkeys]:
66   http://git.tremily.us/?p=dotfiles-public.git;a=blob;f=src/.fluxbox/keys;hb=HEAD
67
68 [[!tag tags/tools]]
69 [[!tag tags/linux]]