Pages / … / IT Operational Procedures
How to install and configure VNC on Ubuntu
Created by Tina Rakotoarivelo, last modified by Daniel Francis Sebastian Charles on Sep 27, 2023
The following instructions will help you set up a VNC server on your Ubuntu desktop and allow you to connect to
desktop session remotely.
This procedure has been tested in Ubuntu 20.04 and validated the same.
Step-1: Install xfce4 (graphical environment) and tightvncserver package on the target desktop
# sudo apt install xfce4 tightvncserver
Step-2: Uninstall tigervnc-server if exist and insall tigervnc-viewer
# sudo apt purge tigervnc-server && sudo apt install tigervnc-viewer
Step-3: Set Password for VNC User
Note: Switch to the target user and set the VNC password
$ vncpasswd
Step-4: Create a xstartup configuration file under target user's home directory:
Note: Create a .vnc directory first if not exists
$ vim /home/$USER/.vnc/xstartup
#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey &
vncconfig -iconic &
exec startxfce4
Step-6: Give execute permission to the xstartup configuration
# sudo chmod +x /home/$USER/.vnc/xstartup
Step-7: Create a system configuration file for the VNC service
Note: Change the User and Group name accordingly to the target user
# vim /etc/systemd/system/
[email protected] [Unit]
Description= Tiger VNC Server service
After=syslog.target network.target
[Service]
Type=forking
User=$USER
Group=$GROUP
Restart=always
ExecStartPre=/bin/bash -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -geometry 1920x1080 -depth 24 :%i
ExecStop=/bin/bash -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
Step-8: Reload the system daemon to reflect the changes
# systemctl daemon-reload
Step-9: Enable VNC service to start automatically after server reboot
Step-10: Restart the VNC service
General Troubleshooting:
If the port 5901 is already used by some other service, then VNC service may fail to start it. Check the log "journalctl -xe"
for more details.
# netstat -tunlp | grep 5901
In order to remediate this port conflict issue, create a new VNC configuration service with port 5902.
Step-1: Stop the existing VNC service
Step-2: Disable the VNC service
Step-3: Enable a new VNC service again
Step-4: Start the VNC service
If the VNC service is failing post config changes, reboot the system once and check it.
Note: Share the same port to the user to access the system along with password.
No labels