Setting up VNC for Ubuntu 16.04 LTS

rmtogether
rmtogether used Ask the Experts™
on
Hi Experts,

My server is Ubuntu 16.04 LTS.
I am following the steps of  https://poweruphosting.com/blog/setup-vnc-server-on-ubuntu/ to set up the VNC server.
However, I fail in the last step like below. Can you please help me with this VNC configuration.

hsu@hcavfb11:~$ sudo systemctl status vncserver@1
● vncserver@1.service - Start TightVNC server at startup
   Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2017-11-24 10:31:34 JST; 18min ago

Nov 24 10:31:34 hcavfb11 systemd[1]: Starting Start TightVNC server at startup...
Nov 24 10:31:34 hcavfb11 systemd[1]: vncserver@1.service: Control process exited, code=exited status=217
Nov 24 10:31:34 hcavfb11 systemd[1]: Failed to start Start TightVNC server at startup.
Nov 24 10:31:34 hcavfb11 systemd[1]: vncserver@1.service: Unit entered failed state.
Nov 24 10:31:34 hcavfb11 systemd[1]: vncserver@1.service: Failed with result 'exit-code'.
hsu@hcavfb11:~$

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. Digital Marketing Executive
Commented:
The last step is creating a VNC Service File as below -

Set up the VNC server as a systemd service. This will make it possible to start, stop, and restart it as needed, like any other systemd service.

First, create a new unit file called
/etc/systemd/system/vncserver@.service

Open in new window

using your favorite text editor:

   
sudo nano /etc/systemd/system/vncserver@.service

Open in new window


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/vncserver@.service 
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=sammy
PAMName=login
PIDFile=/home/sammy/.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

Open in new window


Save and close the file.

Next, make the system aware of the new unit file.

 $   sudo systemctl daemon-reload

Open in new window


Enable the unit file.

  $  sudo systemctl enable vncserver@1.service

Open in new window


Stop the current instance of the VNC server if it's still running.

 
$   vncserver -kill :1

Open in new window


Then start it as you would start any other systemd service.
 $   sudo systemctl start vncserver@1

Open in new window


You can verify that it started with this command:

 
$  sudo systemctl status vncserver@1

Open in new window


If it started correctly, the output should look like this:

Output

vncserver@1.service - TightVNC server on Ubuntu 16.04
   Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2016-04-25 03:21:34 EDT; 6s ago
  Process: 2924 ExecStop=/usr/bin/vncserver -kill :%i (code=exited, status=0/SUCCESS)

...

 systemd[1]: Starting TightVNC server on Ubuntu 16.04...
 systemd[2938]: pam_unix(login:session): session opened for user finid by (uid=0)
 systemd[2949]: pam_unix(login:session): session opened for user finid by (uid=0)
 systemd[1]: Started TightVNC server on Ubuntu 16.04.

Open in new window

Author

Commented:
thank you so much for your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial