This is an old revision of the document!
Ubuntu 18.04 Package https://github.com/LibVNC/x11vnc How to use x11vnc
On remote machine (server)
Gnome Display Manager makes problems for starting a x11 session because of authorizations. Install and use lightdm instead.
sudo apt-get install lightdm
Use dpkg to set the display manager to lightdm.
sudo dpkg-reconfigure lightdm
With lightdm set as display manager we can install x11vnc on the server:
sudo apt-get install x11vnc
On local machine (client)
Install a vncviewer. x11vnc recommends tightvnc.
sudo apt install xfce4 xfce4-goodies xtightvncviewer
Preparing the server
Before the remote client can connect to the server, the server needs to be prepared. On the server a monitor has to be connected. This enables the server to open an actual display, to which the remote client can attach itself to.
If anything else than lightdm is used: Once after every reboot, a user must log in to the server on site, because the virtual display is only launched after the first user's login.
Start server and connect to it (from client)
Launching the x11vnc server and connecting to it via tightvnc is done from the client's site.
The following command launches x11vnc on the server through ssh. Replace the <server_user> with the name of a user with root-rights, and the <server_ip> the the server's IP address.
ssh -t -L 5900:localhost:5900 <server_user>@<server_ip> 'sudo x11vnc -localhost -display :0 -auth guess'
You'll be asked for the user's password first, then for a password of your choice for the vnc session. It's best to store this command in a bash alias, since it is required every time you want to establish a vnc connection. The first part connects to the server via ssh, the latter launches the x11vnc server on display :0, which is the same display as can be seen on the server's physical monitor.
Connecting visually to the x11vnc server from your client machine is done with the following command. As with the previous command, it is advised to create a bash alias for it.
vncviewer -encodings "copyrect tight zrle hextile" localhost:0
Important notes on how to use
If work is done on the remote server, leave the server unlocked and simply close the tightvnc window, this will terminate the client's connection as well as the x11vnc server. Do not lock the screen or log out, because it will close display :0, which prevents any control via vnc.
If an other user is currently connected to the server, it is indicated by your x11vnc-server's console output after entering the ssh password and before setting the vnc password:
bind: Address already in use channel_setup_fwd_listener_tcpip: cannot listen to port: 5900 Could not request local forwarding.
Furthermore, if this is ignored and the x11vnc server is launched anyway, the port will be set to the next free (5901) and display :1, but display :1 doesn't exist. If a second connection it attempted to the same server, it is refused with the following information:
Connected to RFB server, using protocol version 3.8 vncviewer: VNC server closed connection