Configure TigerVNC Server to start with system in Ubuntu GNOME 16.04

10,195

This systemd Unit file worked for me:

[Unit]
Description=Start TigerVNC Server at startup
After=syslog.target network.target

[Service]
Type=forking
User=user
PAMName=login
PIDFile=/home/user/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver :%i -depth 24 -geometry 1920x1080 -nolisten tcp -localhost
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Be sure to replace user with your actual username on lines corresponding to User and PIDFile under [Service].

To adapt it to your needs, please use your preferred display number instead of 4 (as I did) when enabling. Also, ensure that you have initialized the vncserver outside of this service Unit file before starting the service. This would ensure the password, and the necessary files (xstartup, etc.) are created. The easiest way to do that would be to run the command against ExecStart under [Service] in the Unit file. For my case, that translates to:

vncserver :4 -depth 24 -geometry 1920x1080 -nolisten tcp -localhost

Source: I adapted the Unit file from this guide.

Share:
10,195

Related videos on Youtube

Kartik
Author by

Kartik

Updated on September 18, 2022

Comments

  • Kartik
    Kartik over 1 year

    I am trying to configure TigerVNC Server to run on Ubuntu GNOME 16.04.3. I installed the latest version (1.8) of TigerVNC using this post. If I start a server using:

    vncserver :4 -geometry 1920x1080 -depth 24 -nolisten tcp -localhost
    

    it works perfectly. I can connect to display 4 over SSH, and have full access to my computer, without unlocking the real (physical) displays in my lab. Also, I can tune the geometry to match my laptop's display, so everything is perfect.

    Then I tried to get the server to start at startup, using systemd, and I found this post to help me. However, I am running the GNOME desktop, and the settings from the blog are for Unity. I do not have Unity installed on my machine, and I would prefer to avoid it.

    How do I modify steps 7 and 8 in that post to use GNOME desktop instead of Unity? I know that it does not work if they are skipped, as I just get a black screen when I connect remotely.


    In fact, if there is another way to ensure vncserver is started at startup, that will be accepted as answer as well. TigerVNC does install a script called vncserver in /etc/init.d/, but I am not able to launch it using update-rc.d

  • Kartik
    Kartik about 6 years
    Please refer to this question, comments and answer for multiple user support.