systemctl start vncserver@1 gives an error

April 19, 2018 1.8k views
Linux Basics Ubuntu

vncserver@.service:

[Unit]
Description=Start TightVNC 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 -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Error:

root@**server**:~# sudo systemctl start vncserver@1
Job for vncserver@1.service failed because the control process exited with error code.
See "systemctl  status vncserver@1.service" and "journalctl  -xe" for details.
root@**server**:~# 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 Thu 2018-04-19 18:34:49 UTC; 18s ago
  Process: 3369 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=1/FAIL
  Process: 3364 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)

Apr 19 18:34:49 **server** systemd[1]: Starting Start TightVNC server at startup...
Apr 19 18:34:49 **server** systemd[3364]: pam_unix(login:session): session opened for user **user** by (uid=0)
Apr 19 18:34:49 **server** systemd[3369]: pam_unix(login:session): session opened for user **user** by (uid=0)
Apr 19 18:34:49 **server** systemd[1]: vncserver@1.service: Control process exited, code=exited status=1
Apr 19 18:34:49 **server** systemd[1]: Failed to start Start TightVNC server at startup.
Apr 19 18:34:49 **server** systemd[1]: vncserver@1.service: Unit entered failed state.

Any idea what I’m doing wrong?

2 comments
  • To give some additional context, if I setup the vncserver@.service for root, it works just fine. The problem is only when trying to do it for the user I created. To which I did give root access.

  • Some further inspection revealed this: pam_systemd(login:session): Failed to release session: Access denied

1 Answer

The error you shared leads me to believe this may be an issue related to the permissions given to the user account you are running the service under. Are you able to start vncserver normally from the command line?

If you update your systemd service to use the user "root" does the service start properly? (not that I'd recommend keeping this configuration, but testing this can confirm if it's a permissions issue with the user account specified).

Personally I switched from using VNC on my servers to using x2go when needing a remote desktop. It tends to be easier to set up, better performing and more secure since it tunnels over ssh. This script can be used to install and start x2go with xfce on Ubuntu 14.04 and newer.

Have another answer? Share your knowledge.