On Windows machines, if one machine A runs the remote desktop service, and another machine B (which in fact doesn't have to be Windows) runs a remote desktop client - then the user on B can 'steal' control of the session on A, see the app windows which were opened there and interact with them. Note that RDP also allows you to open a new session if there's no existing one, but that's not what the question is about.

My question: How can I achieve the same with A being a Linux machine, running an X server with an X session in progress.


  • A solution need not be based on MSRDP itself, it could be NX, or VNC, or whatever else you like.
  • I'm willing to install software on A and on B, including installation as the root user.
  • Commercial solutions are relevant, though I would rather not resort to them.
  • Solution may involve opening additional ports on A (in addition to, say, port 22 for SSH).
  • Assume the distributions are Debian-based and fairly recent.
  • This question is similar to this one, but it's not the same, since : 1. I'm willing to run services other than just X and 2. In that question, the OP seems more interested in getting specific windows, while for me it's important to see the whole thing.
  • Solutions in which both the users on A and B can interact with the same session are also relevant.
  • install vnc-server on machine A and instal vnc viewer on machine B. – MelBurslan Jan 29 '16 at 18:39
  • @MelBurslan: My limited experience with vnc is that I can use it to start a new X session on A from B, not to connect to an existing one. Can you elaborate more? – einpoklum Jan 29 '16 at 18:41
  • It has been discussed before: serverfault.com/questions/27044/… – Thomas Jan 29 '16 at 18:49

To take control of a running X session you will need to configure your VNC server to connect to the same display as X. Generally, X will be connected to the first display - :0.

You will also need the X Authority for that X session. This can be found by accessing the X Authority file that the remote Display Manager is using. This depends on your Display Manager and can be found using ps aux and grep. For example: psaux | grep Xorg gives you something similar to:

/usr/libexec/Xorg -background none :0 -seat seat0 -auth /var/run/lightdm/root/:0 -listen tcp vt1 -noswitch

Note the -auth option as you'll need it with VNC. You then need to run something like the following as root on the remote computer after installing x11vnc:

/usr/bin/x11vnc -norc -forever -shared -bg -autoport 5900 -auth /var/run/lightdm/root/:0

The easiest way would be to create a service that runs this for you on boot. On distros that use systemd, create a file /etc/systemd/system/x11vnc.service similar to the following:

Description=VNC Server for X11

ExecStart=/usr/bin/x11vnc -norc -forever -shared -bg \
        -autoport 5900 \
        -rfbauth /etc/x11vnc.pass \
        -o /var/log/x11vnc.log \
        -auth /var/run/lightdm/root/:0


Note the -rfbauth option. You'll need to create the password file beforehand using:

$ sudo x11vnc -storepasswd /etc/x11vnc.pass

Alternatively, if you don't feel you need password protected VNC sessions, then simply remove the -rfbauth line.

Enable at boot with:

$ sudo systemctl enable x11vnc.service

Start it manually with:

$ sudo systemctl start x11vnc.service

You can now connect to the remote computer with your VNC client and take over the session.

  • This seems to work, at least in the no-password mode. Now I'll try it with a password set. Also, the VNC server makes numerous suggestions about which options and settings to use; if you have any thoughts on good defaults you could add here, that would be nice (although you've got your +1...). – einpoklum Jan 29 '16 at 19:59
  • I run the above command as a service using systemd, with options for password (-rfbauth) and a log file (-o). Nothing more. – garethTheRed Jan 29 '16 at 20:14
  • Then maybe you should consider the -ncache option. Anyway, thanks. – einpoklum Jan 29 '16 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.