Nov 18, 2017

Creating a VNC Service File

First, create a new unit file called /etc/systemd/system/[email protected] using your favorite text editor:


Copy and paste the following into it. Be sure to change the value of User and the username in the value of PIDFILE to match your username.
/etc/systemd/system/[email protected]
[Unit] Description=Start TightVNC server at startup After=syslog.target network.target [Service] Type=forking User=i88ca PAMName=login PIDFile=/home/i88ca/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Save and close the file.
Next, make the system aware of the new unit file.
  • sudo systemctl daemon-reload
Enable the unit file.

Stop the current instance of the VNC server if it's still running.
  • vncserver -kill :1
Then start it as you would start any other systemd service.

You can verify that it started with this command:

stop it:
$ sudo systemctl stop [email protected]