Xubuntu 16.04.x 64bit – Install Tightvncserver for Multiple Users (Systemd)

Last Modified 2016.09.08

Xubuntu 16.04.x 64bit – Install Tightvncserver for Multiple Users (Systemd)

!!!The following steps assume you are logged in as root!!!

01. Install tightvncserver:
$ apt-get install xfce4-goodies tightvncserver

02. Create .service file for user and set vnc to start for the user on system startup. The format for the service name is “vncserver-USERNAME@:10.service”. Where the “USERNAME” is oddly enough, the user’s name and the “10” in this example designates that the display number is 10, each user should have his own display number; I usually start at 10 to avoid any conflicts with any local system needs:
$ nano /lib/systemd/system/vncserver-USERNAME@:10.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c ‘/usr/bin/vncserver -kill :10 > /dev/null 2>&1 || :’
ExecStart=/sbin/runuser -l USERNAME -c “/usr/bin/vncserver -geometry 1920×1080 :10”
PIDFile=/home/USERNAME/.vnc/%H%i.pid
ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill :10 > /dev/null 2>&1 || :’

[Install]
WantedBy=multi-user.target

03. Setup user. You need to log​ ​into each user’s account and execute the commands below. (Important. The stored password is not encrypted; anyone who has access to the password file can find the plain-text password.):
$ su – USERNAME
$ vncserver ## Would you like to enter a view-only password (y/n)? n
$ exit

04. Start and Enable in Systemd:
$ systemctl daemon-reload
$ systemctl start vncserver-USERNAME@:10.service
$ systemctl enable vncserver-USERNAME@:10.service
$ reboot​​

Notes:

N01. To change a user’s password:
Login to user’s account first
$ vncpasswd

N02. To see all users:
$ cd to “/etc/systemd/system/multi-user.target.wants”

N03. If TAB complete is not working:
$ nano ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

Find the line:

And change it to:

$ sudo reboot

N04. Environment Variable. Any user specific environment variables you want your VNC session to use, must be put in you ~/.vnc/xstartup. To set them globally, put environment variables in /etc/bash.bashrc:
$ nano ~/.vnc/xstartup

You also might need to change #!/bin/sh to #!/bin/bash in your xstartup file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s