home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / doc / HOWTO / mini / Remote-X-Apps < prev    next >
Text File  |  1997-08-12  |  13KB  |  346 lines

  1.  
  2.                        HOW TO RUN REMOTE X APPLICATIONS
  3.                                        
  4. 1. Introduction
  5.  
  6.    
  7.    
  8.    This is (supposed to be) a guide how to do remote X applications. The
  9.    focus is on security issues. I have written this document for several
  10.    reasons.
  11.    
  12.     1. Many questions have appeared on usenet on how to run a remote X
  13.        application.
  14.     2. I see many, many hints of use xhost +hostname or even xhost + to
  15.        allow X connections. _This is ridiculously insecure_, and there
  16.        are better methods.
  17.     3. I do not know of a simple document that describes the options you
  18.        _do_ have. Please inform me <zweije@xs4all.nl> if you know more.
  19.        
  20.    
  21.    
  22.    This document has been written with unix-like systems in mind. If
  23.    either your local or remote operating system are of another flavour,
  24.    you may find here how things work. However, you will have to translate
  25.    examples yourself to apply to your own system(s).
  26.    
  27.    A related document on WWW is What to do when Tk says that your display
  28.    is insecure <http://ce-toolkit.crd.ge.com/tkxauth/>. It was written by
  29.    Kevin Kenny. It suggests a similar solution to X authentication to
  30.    that in this document (xauth). However, Kevin aims more at using xdm
  31.    to steer xauth for you.
  32.    
  33.    The X System Window System Vol. 8 X Window System Administrator's
  34.    Guide by O'Reilly and Associates has also been brought to my attention
  35.    as a good source of information. Unfortunately, I've not been able to
  36.    check it out.
  37.    
  38.    Yet another document much like this, titled Securing X Windows, is
  39.    available at <http://ciac.llnl.gov/ciac/documents/ciac2316.html>.
  40.    
  41.    This is version 0.2.4. No guarantees, only good intentions. I'm open
  42.    to suggestions, ideas, additions, useful pointers, (typo) corrections,
  43.    etc... I want this to remain a simple readable document, though, in
  44.    the best-meant HOWTO style. Flames to /dev/null.
  45.    
  46.    The most recent version of this document is always available on WWW at
  47.    <http://www.xs4all.nl/~zweije/xauth.html>. This document is posted
  48.    irregularly to comp.windows.x. It is also available as the Linux
  49.    Remote X Apps mini-HOWTO at
  50.    <http://sunsite.unc.edu/LDP/HOWTO/mini/Remote-X-Apps>. Linux
  51.    (mini-)HOWTOs are available by http or ftp from sunsite.unc.edu.
  52.    
  53.    
  54.     Contents last updated on 5 August 1997 by Vincent Zweije.
  55.     
  56.    
  57.      _________________________________________________________________
  58.    
  59. 2. The Scene
  60.  
  61.    
  62.    
  63.    You're using two computers. You're using the X window system of the
  64.    first to type to and look at. You're using the second to do some
  65.    important graphical work. You want the second to show its output on
  66.    the display of the first. The X window system makes this possible.
  67.    
  68.    Of course, you need a network connection for this. Preferably a fast
  69.    one; the X protocol is a network hog. But with a little patience and
  70.    suitable protocol compression, you can even run applications over a
  71.    modem. For X protocol compression, you might want to check out dxpc
  72.    <http://ccwf.cc.utexas.edu/~zvonler/dxpc/> or lbx
  73.    <http://sunsite.unc.edu/LDP/HOWTO/mini/LBX>.
  74.    
  75.    You must do two things to achieve all this:
  76.     1. Tell the local display (the server) to accept connections from the
  77.        remote computer.
  78.     2. Tell the remote application (the client) to direct its output to
  79.        your local display.
  80.        
  81. 3. A Little Theory
  82.  
  83.    
  84.    
  85.    The magic word is DISPLAY. In the X window system, a display consists
  86.    (simplified) of a keyboard, a mouse and a screen. A display is managed
  87.    by a server program, known as an X server. The server serves
  88.    displaying capabilities to other programs that connect to it.
  89.    
  90.    A display is indicated with a name, for instance:
  91.      * DISPLAY=light.uni.verse:0
  92.      * DISPLAY=localhost:4
  93.      * DISPLAY=:0
  94.        
  95.    
  96.    
  97.    The display consists of a hostname (such as light.uni.verse and
  98.    localhost), a colon (:), and a sequence number (such as 0 and 4). The
  99.    hostname of the display is the name of the computer where the X server
  100.    runs. An omitted hostname means the local host. The sequence number is
  101.    usually 0 -- it can be varied if there are multiple displays connected
  102.    to one computer.
  103.    
  104.    If you ever come across a display indication with an extra .n attached
  105.    to it, that's the screen number. A display can actually have multiple
  106.    screens. Usually there's only one screen though, with number n=0.
  107.    
  108.    Other forms of DISPLAY exist, but the above will do for our purposes.
  109.    
  110. 4. Telling the Client
  111.  
  112.    
  113.    
  114.    The client program (for instance, your graphics application) knows
  115.    which display to connect to by inspecting the DISPLAY environment
  116.    variable. This setting can be overridden, though, by giving the client
  117.    the command line argument -display hostname:0 when it's started. Some
  118.    examples may clarify things.
  119.    
  120.    Our computer is known to the outside as light, and we're in domain
  121.    uni.verse. If we're running a normal X server, the display is known as
  122.    light.uni.verse:0. We want to run the drawing program xfig on a remote
  123.    computer, called dark.matt.er, and display its output here on light.
  124.    
  125.    If you have csh running on the remote computer:
  126.    
  127.      dark% setenv DISPLAY light.uni.verse:0
  128.      dark% xfig &
  129.      
  130.    Or alternatively:
  131.    
  132.      dark% xfig -display light.uni.verse:0 &
  133.      
  134.    If you have sh running on the remote computer:
  135.    
  136.      dark$ DISPLAY=light.uni.verse:0
  137.      dark$ export DISPLAY
  138.      dark$ xfig &
  139.      
  140.    Or alternatively:
  141.    
  142.      dark$ DISPLAY=light.uni.verse:0 xfig &
  143.      
  144.    Or, of course, also:
  145.    
  146.      dark$ xfig -display light.uni.verse:0 &
  147.      
  148. 5. Telling the Server
  149.  
  150.    
  151.    
  152.    The server will not accept connections from just anywhere. You don't
  153.    want everyone to be able to display windows on your screen. Or read
  154.    what you type -- remember that your keyboard is part of your display!
  155.    
  156.    Too few people seem to realise that allowing access to your display
  157.    poses a security risk. Someone with access to your display can read
  158.    and write your screens, read your keystrokes, and read your mouse
  159.    actions.
  160.    
  161.    Most servers know two ways of authenticating connections to it: the
  162.    host list mechanism (xhost) and the magic cookie mechanism (xauth).
  163.    Then there is ssh, the secure shell, that can forward X connections.
  164.    
  165.   5.1 Xhost
  166.   
  167.    
  168.    
  169.    Xhost allows access based on hostnames. The server maintains a list of
  170.    hosts which are allowed to connect to it. It can also disable host
  171.    checking entirely. Beware: this means no checks are done, so _every_
  172.    host may connect!
  173.    
  174.    You can control the server's host list with the xhost program. To use
  175.    this mechanism in the previous example, do:
  176.    
  177.      light$ xhost +dark.matt.er
  178.      
  179.    This allows all connections from host dark.matt.er. As soon as your X
  180.    client has made its connection and displays a window, for safety,
  181.    revoke permissions for more connections with:
  182.    
  183.      light$ xhost -dark.matt.er
  184.      
  185.    You can disable host checking with:
  186.    
  187.      light$ xhost +
  188.      
  189.    This disables host access checking and thus allows _everyone_ to
  190.    connect. You should _never_ do this on a network on which you don't
  191.    trust _all_ users (such as Internet). You can re-enable host checking
  192.    with:
  193.    
  194.      light$ xhost -
  195.      
  196.    
  197.    
  198.    xhost - by itself does _not_ remove all hosts from the access list
  199.    (that would be quite useless - you wouldn't be able to connect from
  200.    anywhere, not even your local host).
  201.    
  202.    _Xhost is a very insecure mechanism._ It does not distinguish between
  203.    different users on the remote host. Also, hostnames (addresses
  204.    actually) can be spoofed. This is bad if you're on an untrusted
  205.    network (for instance already with dialup PPP access to Internet).
  206.    
  207.   5.2 Xauth
  208.   
  209.    
  210.    
  211.    Xauth allows access to anyone who knows the right secret. Such a
  212.    secret is called an authorization record, or a magic cookie. The
  213.    cookies for different displays are stored together in ~/.Xauthority.
  214.    Your ~/.Xauthority must be inaccessible for group/other users.
  215.    
  216.    Xauth has a clear security advantage over xhost. You can limit access
  217.    to specific users on specific computers. It does not suffer from
  218.    spoofed addresses as xhost does. And if you want to, you can still use
  219.    xhost next to it to allow connections.
  220.    
  221.     5.2.1 Making the Cookie
  222.     
  223.    
  224.    
  225.    If you want to use xauth, you must start the X server with the -auth
  226.    authfile argument. If you use the startx script, that's the right
  227.    place to do it. Create the authorization record as below in your
  228.    startx script. If you don't have urandom, use some other means of
  229.    generating random data. ps -axl will probably do.
  230.    
  231.    Excerpt from /usr/X11R6/bin/startx:
  232.    
  233.      dd if=/dev/urandom count=1|md5sum|sed -e 's/^/add :0 . /'|xauth -q
  234.      xinit -- -auth "$HOME/.Xauthority"
  235.      
  236.    
  237.    
  238.    This is a stripped down version of my startx. See startx(1x),
  239.    xinit(1x), xauth(1x), md5sum(1) to customise your startx script.
  240.    
  241.    If xauth complains about an illegal add line, your version of md5sum
  242.    may be appending a dash (-) to the checksum to indicate that it was
  243.    computed over its standard input. If you can't convince md5sum to
  244.    forget about the dash, you can strip it with sed. Change the argument
  245.    to the sed command as below. In fact, this ought to work with
  246.    non-dash-appending md5sums as well, but it's less understandable.
  247.    _(Thanks Jeffrey)_
  248.    
  249.      ... 's/^\([0-9a-f]*\).*$/add :0 . \1/' ...
  250.      
  251.    
  252.    
  253.    If you can't edit the startx script (because you aren't root), get
  254.    your system adminstrator to set up startx properly, or let him set up
  255.    xdm instead. If he can't or won't, you can make a ~/.xserverrc script.
  256.    If you have this script, it is run by xinit instead of the real X
  257.    server. Then you can start the real X server from this script with the
  258.    proper arguments. To do so, have your ~/.xserverrc use the magic
  259.    cookie line above to create a cookie and then exec the real X server:
  260.    
  261.      #!/bin/sh
  262.      dd if=/dev/urandom count=1|md5sum|sed -e 's/^/add :0 . /'|xauth -q
  263.      exec /usr/X11R6/bin/X "$@" -auth "$HOME/.Xauthority"
  264.      
  265.    
  266.    
  267.    If you use xdm to manage your X sessions, you can use xauth easily.
  268.    Define the DisplayManager.authDir resource in /etc/X11/xdm/xdm-config.
  269.    Xdm will pass the -auth argument to the X server when it starts, and
  270.    all will be well. See xdm(1) for more information. For instance, my
  271.    /etc/X11/xdm/xdm-config has the following line in it:
  272.    
  273.      DisplayManager.authDir: /var/lib/xdm
  274.      
  275.     5.2.2 Transporting the Cookie
  276.     
  277.    
  278.    
  279.    Now that you have started your X session on the server host
  280.    light.uni.verse and have your cookie in ~/.Xauthority, you will have
  281.    to transfer the cookie to the client host, dark.matt.er.
  282.    
  283.    The easiest is when your home directories on light and dark are
  284.    shared. The ~/.Xauthority files are the same, so the cookie is
  285.    transported instantaneously.
  286.    
  287.    If not, you can transport the cookie by means of rsh, the remote
  288.    shell:
  289.    
  290.      light$ xauth nlist :0 | rsh dark.matt.er xauth nmerge -
  291.      
  292.    
  293.    
  294.    This says:
  295.     1. Extract the cookie from your local ~/.Xauthority (xauth nlist :0).
  296.     2. Transfer it to dark.matt.er (| rsh dark.matt.er).
  297.     3. Put it in the ~/.Xauthority there (xauth nmerge -).
  298.        
  299.    
  300.    
  301.    It's possible that rsh doesn't work for you. Besides that, rsh also
  302.    has a security drawback (spoofed host names again, if I remember
  303.    correctly). If you can't or don't want to use rsh, you can also
  304.    transfer the cookie manually, like:
  305.    
  306.      light$ echo $DISPLAY
  307.      :0
  308.      light$ xauth list $DISPLAY
  309.      light/unix:0 MIT-MAGIC-COOKIE-1 076aaecfd370fd2af6bb9f5550b26926
  310.      light$ rlogin dark.matt.er
  311.      Password:
  312.      dark% setenv DISPLAY light.uni.verse:0
  313.      dark% xauth add $DISPLAY . 076aaecfd370fd2af6bb9f5550b26926
  314.      dark% xfig &
  315.      [15332]
  316.      dark% logout
  317.      light$
  318.      
  319.    
  320.    
  321.    See also rsh(1) and xauth(1x) for more information.
  322.    
  323.     5.2.3 Using the Cookie
  324.     
  325.    
  326.    
  327.    An X application on dark.matt.er, such as xfig above, will
  328.    automatically look in ~/.Xauthority there for the cookie to
  329.    authenticate itself with.
  330.    
  331.   5.3 Ssh
  332.   
  333.    
  334.    
  335.    <PLUG CLASS="shameless">
  336.    Authority records are transmitted with no encryption. If you're even
  337.    worried someone might snoop on your connections, use ssh, the secure
  338.    shell. It will do X forwarding over encrypted connections. And
  339.    besides, it's great in other ways too. It's a good structural
  340.    improvement to your system. Just visit <http://www.cs.hut.fi/ssh/>,
  341.    the ssh home page.
  342.    </PLUG>
  343.    
  344.    Who knows anything else on authentication schemes or encrypting X
  345.    connections? Maybe kerberos?
  346.