Ubuntu – VNC server doesn’t start until login

macnetworkingservervnc

I'm trying to set up a VNC connection from my iMac to my (soon to be headless) Mac Mini running Ubuntu 16.10.

I'm using this tutorial: How to Setup X11VNC Server on Ubuntu & LinuxMint

Everything is perfect up through the section "Start X11VNC Server". I run the command from a terminal prompt, the server starts on the Ubuntu box, and I can instantly connect with my VNC client on the iMac (running Chicken).

So, looks good, next section is how to make it so the VNC server starts at boot and I assume that I don't need to be logged in to be able to connect.

I copied the code exactly as shown in the final section, with the one change of my user folder (/home/bryan/.vnc/passwd), saved and rebooted. Tried connecting and the client tells me Could not connect to server 192.168.1.2 port 5900 - The server refused the connection.

But then if I login on the Ubuntu box (currently have it connected up with a monitor, keyboard & mouse), and use the same command from before:

sudo x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/bryan/.vnc/passwd -rfbport 5900 -shared

The iMac can log me in perfectly, exactly the way I want it to.

Why doesn't it seem to load the server at startup, and how can I fix this?

Thanks for any replies!

Best Answer

The tutorial you referenced is outdated, it assumes you're on an older version of Ubuntu with Upstart as the init system (init systems control startup applications). Newer versions of Ubuntu use systemd as the init system.

You need to create a new file at /lib/systemd/system/x11vnc.service and put this inside the file:

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/bryan/.vnc/passwd -rfbport 5900 -shared

[Install]
WantedBy=multi-user.target

After you have created that file you need to enable and reload the service using systemctl by issuing these commands:

sudo systemctl enable x11vnc.service
sudo systemctl daemon-reload

I recommend restarting your system after running those commands.

Reference: http://c-nergy.be/blog/?p=8984

Note: to anyone else having the same issue and creating this file. Be sure to change the ExecStart line to point to your password, i.e. change /home/bryan/.vnc/passwd to /home/yourusername/.vnc/passwd

Related Question