Your next developer desktop with Ubuntu 24.04 and TigerVNC on OCI

Paul Guerin
Oracle Developers
Published in
7 min readOct 8, 2024

There are some types of developer software that only work on a subset of Linux operating systems. For example, Docker will work on Ubuntu and only a few other O/Ss.

Often a developer will also want to login to a graphical environment. And this can be achieved via VNC remote access.

Unfortunately, the procedure to install both the desktop environment, and VNC, differs from other distribution families. eg Fedora, Centos Stream, Red Hat, and Oracle Linux.

In this article, we will detail the procedure to setup VNC remote access for Ubuntu on OCI.

Create the instance

Getting Ubuntu compute instance started with OCI is very easy. And OCI makes several Ubuntu images available.

We can simply choose the latest image available which is Ubuntu 24.04.

Once the instance is ready for use, we can get a nice summary of the virtual machine with Neofetch. Install Neofetch as follows:

# update Ubuntu
sudo apt-get -y update && sudo apt-get -y full-upgrade

# install Neofetch
sudo apt-get -y install neofetch

Then execute Neofetch.

neofetch

From the Ubuntu image, we now have a compute instance that is using the AMD architecture and has 8GB RAM.

Install the desktop environment

To install a desktop environment in Ubuntu (also Debian), we use a special TUI application. That application is named Tasksel.

Install Tasksel as follows:

sudo apt-get -y install tasksel

Next, we can get a listing of all the desktops available from Ubuntu.

tasksel --list-tasks

Tasksel can be used to install several different types of desktop, such as: Gnome, Xfce, or KDE.

The Gnome desktop is available, and that is the one we are interested in, as it is often the default on so many other distributions.

Execute the Tasksel TUI as follows:

# run the TUI to install the desktops
sudo tasksel

Press the ‘spacebar’ to select Gnome.

Then tab, and enter-key to proceed to install the selected desktop.

Install the VNC client viewer

Install the VNC client viewer from here, to your workstation:

https://sourceforge.net/projects/tigervnc/files/stable/

Install the VNC remote access server

For a VNC server, we’ll use Tiger VNC, and it is installed as follows:

sudo apt-get -y install tigervnc-standalone-server dbus-x11

Now configure the password for VNC login. The password does not have to conform to a complex rule, and can be as simple as the word ‘ubuntu’.

Note1: the VNC login password is separate to any password you use for the Linux user account.

Note2: a view-only password is not required.

# setup the VNC password on the server for the remote user
vncpasswd

Next, is to define the mapping between the user and the VNC server. We will assign the Ubuntu user to VNC server display 2.

# Add a user mapping
sudo vim /etc/tigervnc/vncserver.users

:2=ubuntu

Now do a quick test to determine whether the VNC session will start.

# fg = run in the foreground so can cntrl-c easily
# default geometry = 1920x1200
vncserver -fg -geometry=1360x768 -xstartup /usr/bin/gnome-session :2

# optional - if installed, other desktops can be started with:
vncserver -fg -geometry=1360x768 -xstartup /usr/bin/cinnamon-session :2
vncserver -fg -geometry=1360x768 -xstartup /usr/bin/startxfce4 :2

Note: need to wait 10 seconds, or so, for the message that confirms that the TigerVNC server is present for display 2. You won’t be able to connect via VNC until that message is shown!

Also to solve the .Xauthority ‘not writable’ problem, just change the owner of the file to the current user account.

# Change the owner of the $HOME/.Xauthority file
sudo chown ubuntu:ubuntu ~/.Xauthority

With that server available, you can now connect to it, so from another terminal session on your workstation, create a port forward to port 5902.

# once you know the display number then port forward. eg 2
ssh -i ~/.ssh/id_rsa ubuntu@<public-ip> -N -L 5902:localhost:5902&

Then start the VNC client viewer like this, as the port 5902 maps to the VNC server on display 2.

vncviewer localhost:5902

You’ll be asked for a password, and the password for VNC was defined earlier as ‘ubuntu’.

Note: there is a warning about the security of the connection, but we are tunnelling through SSH, which makes the connection secure.

All going well the Gnome desktop will display.

From here we can make sure the internal screensaver for Ubuntu is switched off (from the Settings menu, then select Power).

Now we can stop the VNC server, as we will replicate this functionality from a systemd service instead.

Create the service for the VNC remote access server

Now we are ready to create a systemd service. For an Oracle Linux 8 compute instance, we would create something similar to below.

# Note: for TigerVNC on Oracle 8 the VNC file is as follows:
sudo vim /lib/systemd/system/vncserver@.service

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

[Service]
Type=forking
ExecStartPre=+/usr/libexec/vncsession-restore %i
ExecStart=/usr/libexec/vncsession-start %i
PIDFile=/run/vncsession-%i.pid
SELinuxContext=system_u:system_r:vnc_session_t:s0

[Install]
WantedBy=multi-user.target

However for Ubuntu, the configuration needs to be a little different, and so we will use the following.

# Note: for TigerVNC on Ubuntu
sudo vim /etc/systemd/system/vncserver@.service

[Unit]
Description=Virtual Network Computing (VNC) service
After=syslog.target network.target

[Service]
#Type=forking
#Environment="HOME=/home/ubuntu" "XDG_CURRENT_DESKTOP=GNOME"
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu
PAMName=login
ExecStartPre=-/usr/bin/vncserver -kill %i
#ExecStartPre=dbus-launch --exit-with-session gnome-session
#ExecStartPre=dbus-launch
ExecStart=/usr/bin/vncserver -geometry 1280x800 -xstartup /usr/bin/gnome-session -localhost yes %i
#ExecStop=/usr/bin/vncserver -kill %i
PIDFile=/home/ubuntu/.vnc/%H:%i.pid
#SELinuxContext=system_u:system_r:vnc_session_t:s0

[Install]
WantedBy=multi-user.target

Finish up by reloading the config file, then start the service for display 2.

# reload the configs everytime there is a change
sudo systemctl daemon-reload

# start the service for display 2
# (configured earlier to be the ubuntu account)
sudo systemctl start --now vncserver@:2.service

Wait about 10 seconds, then display all the VNC sessions available:

# confirn the TigerVNC session 2 is started
vncserver -list -cleanstale

Important: if you don’t see the VNC server listed for display 2, then you need to wait a little longer, and repeat the list command.

With that server available, you can now connect to it, so from another terminal session create a port forward as before (or just reuse the other one):

# once you know the display number then port forward. eg 2
ssh -i ~/.ssh/id_rsa-work ubuntu@<public-ip> -N -L 5902:localhost:5902&

Then start the VNC client viewer.

vncviewer localhost:5902

The VNC password was defined earlier as ‘ubuntu’.

Extras

For web development, it may be advantageous to install web browsers in Gnome.

# Note: Gnome already has Firefox browser installed
sudo apt-get install firefox

# Install Chromium
sudo apt-get install chromium-browser

# now add
vim ~/.bashrc
export XAUTHORITY=$HOME/.Xauthority
source ~/.bashrc

Also as an optional extra, you can make the VNC service auto start on reboot of the Ubuntu compute instance.

# enable the service to autostart on reboot
sudo systemctl enable --now vncserver@:2.service

systemctl status vncserver@:2.service

Troubleshooting

Then, if you need to do some troubleshooting, or clean-up, then refer to the following commands.

# Troubleshooting using the ubuntu user
systemctl status vncserver@:2.service
journalctl --unit=vncserver*

# Kill a VNC server for troubleshooting purposes
vncserver -kill $DISPLAY

# List the VNC servers
vncserver -list -cleanstale

# cleanup, if you installed other desktops
sudo apt-get remove ubuntu-desktop

# removes dependencies of ubuntu-desktop
sudo apt-get autoremove

Lastly, for reference, the official TigerVNC HOWTO doco is here:

Paul Guerin has presented at some of the world’s leading Oracle conferences, including Oracle Open World 2013. Since 2015, his work has been featured in the IOUG Best Practices Tip Booklet, and in publications from AUSOUG, Oracle Technology Network, Quest, and Oracle Developers (Medium). He was awarded as a most valued contributor for the My Oracle Support Community (2019), and continues to be a participant of the Oracle ACE program.

Oracle Developers
Oracle Developers

Published in Oracle Developers

Aggregation of articles from Oracle engineers, Groundbreaker Ambassadors, Oracle ACEs, and Java Champions on all things Oracle technology. The views expressed are those of the authors and not necessarily of Oracle.

No responses yet

What are your thoughts?