Short Tip: Access a running X session via x11vnc

cube-with-matrix
There are thousands of ways to access a running Linux machine. In case you need for whatever reason remote access to a full session, one easy way is x11vnc. Given that the user is already logged into X, access the machine via ssh, log in as the user who opened the X session, and enter:

x11vnc -display :0

Now you can access the machine with a vnc viewer, for example with 192.168.123.45:0. Beware however that this configuration has no encryption via network – and no vnc password at all!

In case you need to access a running login manager (where no user is logged in yet) first get the authentication file of the running X and hand it over to x11vnc (as root):

host:~# ps x|grep X
 1425 tty8     Ss+    0:01 /usr/bin/X -br :0 vt8 -auth /var/run/xauth/A:0-1EkR5c
host:~# x11vnc -display :0 -auth /var/run/xauth/A:0-1EkR5c

A good client to connect to the running vnc session is KDE’s krdc.

8 thoughts on “Short Tip: Access a running X session via x11vnc”

  1. If you’re running KDE 4, I can very much advice krfb for logging into a running X session. It has the advantage of being able to create invitations: passwords for vnc access that are only valid for 1 login. Quite convenient for technical support.

  2. I also add -localhost so that it only accepts connections from localhost, so you can only access it from through an ssh tunnel for example.

    Also -rfbauth so that it will ask for a password

    The following allows me to access the login screen:
    sudo x11vnc -localhost -display :0 -rfbauth /root/.vnc/passwd -auth /var/run/xauth/A\:0-*

  3. Has anyone had problems running KDE4 within a VNC server’s X display? For me the display was far from pretty. I suspect that the colour depth was too low, but haven’t confirmed that.

    Running KDE4 with no machine’s NX server worked fine.

    It may be a matter of adjusting the VNC server’s settings, but it would be better if the defaults were sufficient. I was using the “vnc4server” package with kubuntu 8.04. I must try it with kubuntu 8.10 when I get the time.

  4. rscheepmaker, didn’t knew the one-password-thing, that’s really handy! Although, in this case, it was a KDE 3 to KDE 4 setup, but still….

    Anonymous, yes, the localhost makes quite some sense – as does the password. I tried to highlight that the security problems in this method are huge and that it should only be used in non-productive networks which cannot be accessed from the outside.

    Paul, haven’t tried that. Maybe you should ask at a KDE/Kubuntu forum…

  5. I’ve been using ‘vnc4server’ on debian/ubuntu and it works very well. Also, it doesn’t need a dedicated DISPLAY; it shares the current DISPLAY so I think it’s a good feature.

    The instructions:
    1) sudo apt-get install vnc4server
    2) add a ‘Load “vnc”‘ line at the Modules section at /etc/X11/xorg.conf
    3) add a password file at the Screen section:
    Option “passwordFile” “/etc/X11/vnc.passwd” (p.ex)
    The passwords on this file are managed by the command ‘vnc4passwd’
    4) restart X… and profit!

    Hope it helps!
    Greets,
    Antonio

  6. How are you doing the code block with “SyntaxHighlighter”? That is the only thing keeping me from moving to wordpress.

Comments are closed.