VNC (Virtual Network Computing) is a visual connection system that enables you to interact with the graphical desktop environment of a remote PC using a mouse and a keyboard.
If you have worked with Microsoft Remote Desktop Protocol (RDP) before, think of VNC as an open-source alternative.
VNC is quite a lifesaver for many who are not comfortable working from the command-line and need to manage files, install software and configure settings on a remote server.
In this tutorial we will go step-by-step through installing and configuring the VNC Server on an Ubuntu 22.04 or 20.04 machine, and we’ll look at how we can connect to it via VNC desktop client on our other PC using a secure SSH tunnel.
We will also install some of the most popular desktop environments and configure the VNC server to use them.
Let’s dive in and get started.
Table of Contents
Prerequisites
- A machine running Ubuntu 22.04 or 20.04 to which we’ll connect.
- Acting as a non-root sudo user for security reasons. You can see our tutorial on creating a sudo user in Ubuntu if you need to.
- A VNC Client (also called VNC Viewer) which is the software that you’ll run on your local machine and will enable you to control your VNC server remotely. There are some popular VNC viewers that you can choose from. The one I’m using in this tutorial is Real VNC Viewer.
It’s available for Windows, macOS, Linux, Android, and others. You can choose your OS and download Real VNC Viewer here. If you’re on Linux then I prefer Remmina.
Step 1: Install a Desktop Environment
If you intend to connect via VNC to an Ubuntu 22.04 or 20.04 server, then you’ll notice that the server doesn’t come with a preinstalled Desktop Environment. On booting up, you will get a command-line interface to execute your commands.
However, that doesn’t mean you can install one.
As of writing this post, there are several Linux desktop environments available for you to install. They include GNOME desktop, KDE Plasma Desktop, Mate Desktop, Budgie Desktop, Xfce/Xubuntu Desktop, Cinnamon Desktop, and many more.
For this particular post, we will install the XFCE desktop environment. It is fast, stable, and easy to use.
XFCE is very popular and lightweight. If you’d like to install a different desktop environment right away, you can jump to our section below, on installing and configuring other desktop environments with VNC: Configuring VNC to Use other Desktop Environments
You can also install multiple desktop environments at the same time, and just switch between them. However, you may end up with bugs or conflicts, depending on the desktop environments you have simultaneously installed.
After establishing an SSH connection to your server, execute the following command to update your package index:
sudo apt update
Next we’ll run the following command to install xfce4
and xfce4-goodies
:
sudo apt install xfce4 xfce4-goodies
xfce4-goodies
is an additional package for XFCE Desktop Environment, which brings a lot more advanced enhancement.
You will see a prompt to select a display manager for your newly installed XFCE Desktop Environment during the installation.
Select any display manager and press Enter.
Step 2: Install VNC server
After successfully installing the XFCE desktop environment, we can proceed to install the VNC server.
There are several VNC servers available for Linux today. They include TightVNC, x11VNC, and TigerVNC.
For this particular tutorial, we will install the TigerVNC server.
- Initially I tried TightVNC and got it to work with XFCE, LXQt, LXDE, KDE Plasma, and Gnome Flashback, but struggled with GNOME 3 and Budgie. I didn’t try MATE or Cinnamon, however.
Install TigerVNC on Ubuntu
To install TigerVNC execute the command below:
sudo apt install tigervnc-standalone-server
After a successful installation, we need to perform the initial VNC configuration, set up a VNC access password and initialize the VNC server.
Execute the command below to initialize the VNC server instance and set up a password. Assuming you are acting as a non-root sudo user, do NOT execute this command with sudo
:
vncserver
You will require a password to access your desktops. Password: Verify:
After setting up the password, you will get a prompt to set a View-Only password. That means anybody who accesses the VNC server with a view-only password will not be able to VNC desktop with either Mouse or Keyboard.
For this particular post, we won’t set up a view-only password. I will just type N and hit Enter.
Would you like to enter a view-only password (y/n)? N /usr/bin/xauth: file /home/edxd/.Xauthority does not exist New 'bytexd:1 (edxd)' desktop at :1 on machine bytexd Starting applications specified in /etc/X11/Xvnc-session Log file is /home/edxd/.vnc/bytexd:1.log Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/edxd/.vnc/passwd :1 to connect to the VNC server.
We can see this process lists the connection information for our VNC server from the message above. Additionally, it started the VNC server at port 5901
, which is the display port. This port (5901) is referred to as :1
.
If you create additional VNC server instances, they will be presented as port 5902 as :2
, port 5903 as :3
, and so on.
Up to this point, our VNC server is up and running. However, it cannot give us access to a graphical interface since it’s not configured to launch our XFCE desktop environment;
vncpasswd
Step 3: Configure the VNC server
Up to this point, we have successfully installed the VNC server and even set up a password.
Now we need to configure the commands that will be executed by the server every time we start a VNCV instance.
One main goal is telling VNC which Desktop Environment to connect and use – in this case, XFCE.
To get started, let’s kill the running VNC instance that we launched in Step 2 above running on port 5901
. Execute the command below:
vncserver -kill :1
Killing Xtigervnc process ID 28634... success!
If another instance were running on another port, say 5902 or 5903, we would execute the commands vcnserver -kill :2
and vncserver -kill :3
, respectively.
To configure VNC, we will need to create a file called xstartup
file in the .vnc folder under the home directory (~/.vnc/xstartup
). This is where we’ll configure what desktop environment we want the VNC server to use.
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
, and create a new file.Now, let’s create and open a new xstartup
file with the nano
editor. Execute the commands below:
nano ~/.vnc/xstartup
Add the lines below on the editor:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/startxfce4 [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Save the file (Ctrl + O, then Enter) and Exit (Ctrl + X).
Lastly, we need to make this file executable. Run the command below:
chmod +x ~/.vnc/xstartup
Once done, proceed to restart the VNC server with the command below.
vncserver -localhost no :1
New 'bytexd:1 (edxd)' desktop at :1 on machine bytexd Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/edxd/.vnc/passwd :1 to connect to the VNC server.
The above command launches a VNC server instance on port 5901.
-localhost no
By default, TigerVNC accepts connection only from 127.0.0.1
or localhost
, for security reasons. Since we’re just testing now, we added -localhost no
to be able to access the server via VNC from the outside.
We’ll cover this in a little bit more detail further in this article.
As such, before proceeding and looking at how to create a secure connection, let’s test the VNC server.
Connecting to your VNC Remote Desktop
Launch your VNC Client (or VNC Viewer) application on your local machine and connect to the VNC server using server_ip_address:1
or server_ip_address:5901
.
In my case, I will use 149.28.227.198:1
(I’m using a Vultr server), and my VNC Client is Real VNC Viewer, which supports many operating systems including Windows, macOS and Linux.
From the image above, you can now see our VNC server is well configured, and we can access it from our local machine.
Close the VNC client desktop session and kill the VNC instance on the server using the command below:
vncserver -kill :1
Step 4: Establish a secure connection to the VNC Desktop
To establish a secure connection, restart your VNC server by simply running vncserver
without the -localhost no
option as shown below.
vncserver
New 'bytexd:1 (edxd)' desktop at :1 on machine bytexd Starting applications specified in /home/edxd/.vnc/xstartup Log file is /home/edxd/.vnc/bytexd:1.log Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/edxd/.vnc/passwd :1 to connect to the VNC server.
By default, TigerVNC by default, when you don’t run -localhost no
, binds the server to your Ubuntu 22.04 / 20.04 server loopback interface. That ensures that the VNC server only accepts connections incoming from the server where it is installed.
To get around this and connect to the VNC server from our local machine, we will establish an SSH tunnel from our local machine to the server. That is also an additional layer of security as only users with SSH access to the server can connect to the VNC server.
We’ll set up our SSH tunnel in one of two ways, depending on your preference – by running a command in your terminal or by configuring it in Putty. You can choose whichever one you prefer.
Set up an SSH Tunnel with Your Terminal
You’re probably familiar with your terminal if you are on Linux or macOS. On Windows you can use PowerShell or a terminal emulator such as Cmder.
Execute the command below on your local machine terminal emulator.
ssh -L 59000:localhost:5901 -C -N -l server_user_name server_ip_address
Remember to replace the server_user_name and server_ip_address accordingly. In my case, I will execute the command below:
ssh -L 59000:localhost:5901 -C -N -l edxd 149.28.227.198
When you are done with using the VNC Desktop session, you can kill it using Ctrl + C. Alternatively; you can add a -f
argument which runs SSH tunneling in the background.
Lets, dissect the SSH tunneling command above:
-L 59000:localhost:5901
: The -L argument specifies the post on your local computer (ours is 59000) to the given host (localhost) and port (5901) on the destination server (server_ip_address).
Note: The local port, 59000, can be any number but not more than 65535 and not running another service.-C
: This argument speeds up processes and minimizes resource usage.-N
: This argument prevents execution of remote commands and tells SSH to only forward ports.-l server_user_name server_ip_address
: This line specifies the user you will use to login to the server. Make sure the user is non-root and doesn’t have root privileges.
Now to connect securely to your VNC server, launch the VNC client application and connect with the address localhost:59000
:
Set up an SSH Tunnel with Putty
If you are connecting to your server using Putty, create an SSH tunnel using the procedure below. Launch Putty and enter your server’s address in the session > hostname.
On the left side of the Putty window, scroll down and get to the SSH option. Extend it and select the Tunnels option. Enter the details as shown in the image below—Port 59000
as the source port and localhost:5901
as the destination address.
When done, click Add, then Open/Apply to create the SSH tunnel. You can now connect to the VNC server using the VNC client address: localhost:59000
.
Step 5: Setting up the VNC as a system service
The advantage of setting up VNC as a service is that we can start, stop, restart or even view its status (whether it’s running or not) just like we would for other system services. We will also use systemd to launch our VNC server on boot.
To get started, let’s create a unit file called [email protected] using the command below:
sudo nano /etc/systemd/system/[email protected]
Paste the lines below and remember to replace the YOUR_USERNAME
text with your username, and -depth 24 -geometry 1280x800
with the depth and geometry you prefer.
- -depth: represents the color depth, in bits per pixel. The value can be between 8 and 32.
- -geometry: the width and height of the desktop.
[Unit] Description=Start TigerVNC server at startup After=syslog.target network.target [Service] Type=forking User=YOUR_USERNAME Group=YOUR_USERNAME WorkingDirectory=/home/YOUR_USERNAME PIDFile=/home/YOUR_USERNAME/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Save the file (Ctrl + O, then Enter) and Exit (Ctrl + X).
Now we need to make the system aware of our new unit file. Execute the commands below:
sudo systemctl daemon-reload sudo systemctl enable [email protected]
Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /etc/systemd/system/[email protected]
With that done, we can now start, stop and restart our VNC server as a system service. To test this, let’s first stop the instance that we had launched previously with the command below:
vncserver -kill :1
Once done, let’s now start the VNC server as a service. Execute the command below:
sudo systemctl start [email protected]
To check its status and confirm whether its running or not, use the command below:
sudo systemctl status [email protected]
● [email protected] - Start TigerVNC server at startup Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled) Active: active (running) since Fri 2021-07-23 11:37:59 UTC; 5s ago Process: 83157 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=0/SUCCESS) Process: 83162 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :1 (code=exited, status=0/> Main PID: 83170 (Xtigervnc) Tasks: 166 (limit: 2270) Memory: 236.5M CGroup: /system.slice/system-vncserver.slice/[email protected] ├─83170 /usr/bin/Xtigervnc :1 -desktop bytexd:1 (edxd) -auth /home/edxd/.Xauthority -geometry 1280x80> ├─83180 xfce4-session ├─83191 /usr/bin/dbus-launch – sh-syntax – exit-with-session xfce4-session ├─83192 /usr/bin/dbus-daemon – syslog – fork – print-pid 5 – print-address 7 – session ├─83198 /usr/libexec/at-spi-bus-launcher ├─83203 /usr/bin/dbus-daemon – config-file=/usr/share/defaults/at-spi2/accessibility.conf – nofork – > ├─83207 /usr/lib/x86_64-linux-gnu/xfce4/xfconf/xfconfd ├─83213 /usr/libexec/at-spi2-registryd – use-gnome-session ├─83219 /usr/bin/ssh-agent -s ├─83223 xfwm4 ├─83227 /usr/libexec/gvfsd ├─83238 xfsettingsd ├─83239 xfce4-panel ├─83245 Thunar – daemon ├─83250 xfdesktop ├─83251 /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 /usr/lib/x86_64-linux-gnu/xfce4/panel/plugi> ├─83252 /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 /usr/lib/x86_64-linux-gnu/xfce4/panel/plugi> ├─83253 /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 /usr/lib/x86_64-linux-gnu/xfce4/panel/plugi> ├─83256 /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 /usr/lib/x86_64-linux-gnu/xfce4/panel/plugi> ├─83257 /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 /usr/lib/x86_64-linux-gnu/xfce4/panel/plugi> ├─83270 /usr/lib/x86_64-linux-gnu/xfce4/notifyd/xfce4-notifyd ├─83273 /usr/libexec/geoclue-2.0/demos/agent ├─83281 xiccd ├─83282 /usr/lib/x86_64-linux-gnu/tumbler-1/tumblerd ├─83283 /usr/bin/python3 /usr/share/system-config-printer/applet.py ├─83287 nm-applet ├─83289 /usr/libexec/evolution-data-server/evolution-alarm-notify ├─83302 /usr/libexec/dconf-service ├─83308 xfce4-power-manager ├─83339 /usr/libexec/evolution-source-registry ├─83348 /usr/libexec/goa-daemon ├─83356 /usr/libexec/goa-identity-service ├─83363 /usr/libexec/evolution-calendar-factory ├─83376 /usr/libexec/evolution-addressbook-factory ├─83394 /usr/libexec/gvfs-udisks2-volume-monitor ├─83400 /usr/libexec/gvfs-goa-volume-monitor ├─83405 /usr/libexec/gvfs-gphoto2-volume-monitor ...
From the image above, we can see that we have successfully started VNC as a service.
That’s it! You have successfully installed and configured the VNC server on Ubuntu 22.04 / 20.04 LTS, and you can now manage it just like any system service.
Configuring VNC to Use Other Desktop Environments (And Switching Between Them)
To configure VNC to use a desktop environment with TigerVNC we have to:
- Install the desktop environment on our Ubuntu 22.04 / 20.04 machine
- Appropriately edit the ~/.vnc/xstartup file where we tell VNC what applications to start on our behalf when it creates a new desktop. In this section, where we mention what contents to add to the ~/.vnc/xstartup file, we’ll assume the file is empty.
- Restart the VNC server after you’ve edited the ~/.vnc/xstartup file.
If you set up the VNC service as a system service you can restart it by running:sudo systemctl start [email protected]
If you don’t have it set up as a system service then you can just kill the VNC instance and start it again:
vncserver -kill :1 vncserver
Please keep in mind that if you install multiple desktop environments on the same machine, then you may encounter bugs or conflicts, depending on which you have installed.
Configure VNC to Use GNOME
To install GNOME on Ubuntu 22.04 / 20.04 we’ll run:
sudo apt install gnome-session gnome-terminal
And to configure VNC to use GNOME create a new ~/.vnc/xstartup file or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/gnome-session [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server, and when you connect to it you should be using GNOME.
Here’s how the GNOME minimal installation looks like in my case:
And this is how the full GNOME desktop looks like, if you install it with the following command:
sudo apt install ubuntu-desktop
This is how the full GNOME Desktop install it looks like:
Configure VNC to Use XFCE
We covered this initially in the tutorial, but will add it here too, so the article is more easily skimmable.
To install XFCE run:
sudo apt install xfce4 xfce4-goodies
To configure VNC to use XFCE create a new ~/.vnc/xstartup file or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/startxfce4 [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using XFCE.
This is what XFCE looks like:
Configure VNC to Use LXQt
To install LXQt run:
sudo apt install lxqt
To configure VNC to use LXQt create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/startlxqt [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using LXQt.
This is what LXQt looks like in my case:
Configure VNC to Use LXDE
To install LXDE run:
sudo apt install lxde
To configure VNC to use LXQt create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/startlxde [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using LXDE.
This is what LXDE looks like in my case:
Configure VNC to Use MATE Desktop
To install MATE Desktop run:
sudo apt install ubuntu-mate-desktop
To configure VNC to use MATE Desktop create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/mate-session [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using MATE Desktop.
This is what MATE Desktop looks like in my case:
Configure VNC to Use Budgie
To install Budgie run:
sudo apt install ubuntu-budgie-desktop
To configure VNC to use Budgie create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/budgie-session [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using Budgie.
This is what Budgie looks like in my case:
Configure VNC to Use KDE Plasma Desktop
To install KDE Plasma Desktop run:
sudo apt install kde-plasma-desktop
To configure VNC to use KDE Plasma Desktop create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/startplasma-x11 [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using KDE Plasma Desktop.
This is what KDE Plasma Desktop looks like in my case:
Configure VNC to Use Cinnamon
To install Cinnamon run:
sudo apt install cinnamon-desktop-environment
To configure VNC to use Cinnamon create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/cinnamon-session [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Make the file executable in case it isn’t already:
chmod +x ~/.vnc/xstartup
Now restart the VNC server and next time you connect you should be using Cinnamon.
This is what Cinnamon looks like in my case:
Configure VNC Deepin Desktop Environment (DDE)
To install Deepin first add the stable PPA for DDE:
sudo add-apt-repository ppa:ubuntudde-dev/stable
Update your package index:
sudo apt update
Install Deepin Desktop Environment:
sudo apt install ubuntudde-dde
To configure VNC to use Deepin create a new ~/.vnc/xstartup file, or edit the existing one, and paste in the following:
#!/bin/bash unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS export XKL_XMODMAP_DISABLE=1 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export [email protected]=fcitx #__using_dde__ session=startdde #__enable_clipboard_sync__ if [ -f /usr/bin/autocutsel ] then /usr/bin/autocutsel -fork fi #__deepin_uos_activator__ if [ -f /usr/bin/uos-activator ] then /usr/bin/uos-activator & fi #__enable_fcitx__ if [ -f /usr/bin/fcitx ] then (sleep 15 && /usr/bin/fcitx) & fi #__kill_user_apps_duplicated__ killall -9 v2ray & exec dbus-launch $session
This is what Deepin looks like in my case:
Conclusion
I believe this guide has given you a step-by-step guide on installing and configuring a VNC server on Ubuntu 22.04 or 20.04. Feel free to share any additional VNC configuration tips with our readers or ask any questions in the comments below or by contacting us.
I followed the steps exactly,
It shows only a black screen hen I access from localhost.
But i works in localhost when I run vncserver as sudo
The article says to start the server for testing using “vncserver localhost -no :1” … however that should be “vncserver -localhost no :1”
Hi. Apologies for that. I don’t know what I was thinking.
Thanks so much for pointing that out.
It’s corrected now.
Thank you for your post but it doesn’t work completely with Zorin OS 16 based on Ubuntu 20.04… or at least I can’t make it work completely.
I tried to explain my issue in here : https://gist.github.com/spinxz/1692ff042a7cfd17583b?permalink_comment_id=4097680#gistcomment-4097680
If you have any comment to help me solve this issue, I’d be thankfull.
Hi Thatoo,
I’ve also tried it with ZorinOS and the same thing happens. When running it as a service I get the same error with GNOME, otherwise it works.
I haven’t been able to find a solution. Have you had any success with this?
Hello EdXD,
No I haven’t.
However, I was wondering if there was not a conflict with the builtin VNC system of Zorin OS 16 but I don’t know where to look at and how to disable it before testing again TigerVNC.
Great post. Thanks.
Hi, Eric. Thank you for the feedback! I hope it was useful to you.
good article explain in detail and very useful
I’ve searched and tried many ways. until the end of this article
thank you very much
Thank you for the kind words! I’m glad it worked for you!
Hey can you add a tutorial for Deepin OS’s Deppin Desktop environment? It’s a good looking environment
Hello. Thanks a lot for the suggestion.
I added Deepin just now, however I couldn’t get it to work for Ubuntu 22.04, only for 20.04.
Hope that works for you.
Thanks for the guide! A couple things didn’t work for me in Ubuntu 22.04, so I though I’d share the alterations that were necessary.
First, the version of systemd which ships with Ubuntu 22.04 (specifically, that’s version 249) does not use a shell to interpret “ExecStartPre”:
> Note that shell command lines are not directly supported. If shell command
> lines are to be used, they need to be passed explicitly to a shell
> implementation of some kind.
source: https://www.freedesktop.org/software/systemd/man/systemd.service.html
That means the following line won’t work (because the tokens intended to trigger process output redirection are actually passed as arguments to vncserver):
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
That line should instead read:
ExecStartPre=-bash -c “/usr/bin/vncserver -kill :%i > /dev/null 2>&1”
Second, the version of TigerVNC which is available in the Ubuntu 22.04 “apt” repository (specifically, that’s version 1.12.0) doesn’t create a PID file at the path referenced by this tutorial. From man tigervncserver:
> ~/.vnc/:.pid
> Identifies the VNC server process ID, used by the -kill option.
…where “rfbport#” is defined as
> -rfbport rfbport#
> Specifies the TCP port on which Xtigervnc listens for connections
> from viewers (the protocol used in VNC is called RFB – “remote
> framebuffer”). The default is 5900 plus the display number display#.
That means the following line won’t work (since systemd will expand the value to a non-existent file):
PIDFile=/home/mike/.vnc/%H:%i.pid
One small but inelegant fix would be to approximate integer addition using string concatenation:
PIDFile=/home/mike/.vnc/%H:590%i.pid
This will break if using a systemd instance name greater than 9, though. A safer (but more drastic) solution would be to define the unit using the “simple” type. Crucially, this requires adding the -fg argument:
[Service]
User=YOUR_USERNAME
Group=YOUR_USERNAME
WorkingDirectory=/home/YOUR_USERNAME
ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1280×800 -localhost :%i
Thanks again!
The xstartup for KDE is wrong :\
Hi Bard. Could you please elaborate? It worked 3 weeks ago.
UPDATE: Apologies. You’re right. It had cinnamon-session. I must’ve copied it by mistake. It should be fixed now.