Setting up a VNC server on Ubuntu

I had the need to VNC into my old Ubuntu machine. The built in Desktop Sharing application, which I think is Vino, was not able to properly share to my Mac. I needed something else. I decided to use x11vnc because of the solid reviews I saw when I did a quick search.  It lacks the nice GUI options but it seems to get the job done.

Install it
sudo apt-get install x11vnc

Setup a password
This will store the password in ~/.vnc/passwd
x11vnc -storepasswd

There are other options to store it in different locations but you can see those options by just running x11vnc with no options.

Start x11vnc
x11vnc -usepw -many -nap
-usepw uses the password you just created
-many allows for multiple connections
-nap if activity is low take longer naps between screen pools to cut down load when idle

other options
-bg go into background after starting up
-loop restarts x11vnc in the event it is terminated
-display :X the display to connect to where X is usually 0
-noxdamage
all options

Some examples:
x11vnc -usepw -many -nap -loop -noxdamage
x11vnc -usepw -many -nap -noxdamage -bg
x11vnc -usepw -many -nap -noxdamage -display :0 -bg
The last one is what I typically use.

Tunnel through SSH
On your ssh server
ssh -f -L5900:127.0.0.1:5900 USER@HOST “x11vnc -usepw -many -nap -noxdamage -display :0 -listen 127.0.0.1”
or
ssh -f -L5901:127.0.0.1:5900 wincen@t60 “x11vnc -usepw -many -nap -noxdamage -display :0 -listen 127.0.0.1”

Replace USER and HOST with your username and server’s hostname.
-L5900 tells ssh to set up forwarding on port 5900.  The tunnel’s endpoint will be 127.0.0.1:5900 on our vnc server.  Notice -listen added to the end of my x11vnc command, this is so that x11vnc is specified to listen for connections from 127.0.0.1 and not elsewhere; you could also use -localhost instead of -listen.  I run into problems using -L5900 and use -L5901 instead.  The -f options tells ssh to run this in the background; you won’t be able to use -bg with x11vnc anymore.

Now you’ll want to connect to the ssh tunnel on your client machine (source).
ssh -N -p 22 USER@HOST -L 5901:localhost:5900
where USER is the username on the vnc server and HOST is the vnc server.  This creates a tunnel on your client machine:5901 to the vnc server:5900.

When I use the mac’s vnc client I connect via Go->Connect to Server and enter vnc://localhost:5901

The best client I found thus far is vncviewer.  I connect using
VNC Server: localhost:5901

Troubleshooting SSH Tunneling
If you run into ssh tunneling issues enable it by following this guide
https://help.ubuntu.com/community/SSH/OpenSSH/Configuring#Forwarding

If you run into this error it’s probably the Ubuntu firewall
x11vnc channel 1008: open failed: administratively prohibited: open failed
TODO: solution
Workaround: disable firewall with sudo ufw disable

If that doesn’t work try using port 5901:
ssh -L5901:127.0.0.1:5900 wincen@t60 “x11vnc -usepw -many -nap -noxdamage -display :0 -listen 127.0.0.1”

Run Automatically after logging in
TODO

Additional Information
http://www.karlrunge.com/x11vnc/index.html
http://ubuntuforums.org/showthread.php?t=45565
https://wiki.archlinux.org/index.php/X11vnc
http://allthingsgeek.wordpress.com/2012/12/01/using-ssh-and-x11vnc-to-tunnel-vnc-between-linux-hosts/
http://www.howtogeek.com/115116/how-to-configure-ubuntus-built-in-firewall/
http://www.cs.utexas.edu/users/habals/blog/index.php/archives/22

Leave a comment