Kubuntu 20.04 LTS - How to set up TigerVNC server
Intro
In this tutorial I’ll show you how to configure a remote desktop session, using TigerVNC
in Kubuntu 20.04 LTS
.
Install needed packages
Assuming you already have KDE installed as default Desktop Environment, you will just need to install the TigerVNC packages:
sudo apt install tigervnc-standalone-server
Configuration
Add the user you will be using in the remote session (e.g. vncuser
). I recommend to avoid using root
or sudo
-enabled users for this:
sudo adduser vncuser
Now, login as vncuser
:
su - vncuser
and set a password that will be used to access the Remote session.
vncpasswd
Start a new session to test that TigerVNC works:
vncserver -localhost no
You should be able to see it running using the next command:
vncserver -list
Something like this:
vncuser@kubuntu:~$ vncserver -list
TigerVNC server sessions:
X DISPLAY # RFB PORT # PROCESS ID
:1 5901 19314
meaning that a VNC session is running on the virtual display :1
, accessible using port 5901
(5900 + whatever number of the display).
If everything works fine, you can now kill that session:
vncserver -kill :1
Now, create a service file to enable VNC
to run automatically:
sudo nano /etc/systemd/system/vncserver@.service
adding the following text, changing the user name (in this case vncuser
) to the appropriate user name:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=vncuser
Group=vncuser
WorkingDirectory=/home/vncuser
PIDFile=/home/vncuser/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver :%i -localhost no -geometry 1280x800
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
save and exit (Ctrl + x
and y
).
You can also edit the default resolution of the session (in this case 1280x800
) to whatever value you need. If using TigerVNC Viewer, every time you resize the client window, the native resolution of the remote session will adapt automatically.
In some other tutorials, the commands to kill an existing VNC session
/usr/bin/vncserver -kill %i
can be found written with a :
before the %i
, like this:
/usr/bin/vncserver -kill :%i
The service file mentioned above will not have this, as the name of the running service will contain the columns in it, i.e.:
vncserver@:1.service
instead of:
vncserver@1.service
Next, update the list of services:
sudo systemctl daemon-reload
Enable the recently created service and start it with one command:
sudo systemctl enable vncserver@1.service --now
In Kubuntu (and Ubuntu family distros in general) you shouldn’t need to open the firewall port to use TigerVNC. Otherwise, to open port 5901
, use the following command:
sudo ufw allow from any to any port 5901 proto tcp
You should be able to access the remote session using a VNC viewer, like TigerVNC viewer.