Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mixalbl4-127/4f5ab6744be6f98555f3e29f1cfc7050 to your computer and use it in GitHub Desktop.
Save mixalbl4-127/4f5ab6744be6f98555f3e29f1cfc7050 to your computer and use it in GitHub Desktop.
VNC+xfce4 setup on Ubuntu server 22.04 LTS

Setup

Install xfce4

sudo apt update
sudo apt install xfce4 xfce4-goodies

Install TigerVNC -

$ sudo apt install tigervnc-standalone-server

Configure VNC Server by running

$ vncserver

This will setup a password to access the server through a remote session.

Create/add this file ~/.vnc/xstartup with the following contents -

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4

Make the file executable -

$ chmod +x ~/.vnc/xstartup

Create a new service file to configure VNC Server to startup as a service on boot -

$ sudo nano /etc/systemd/system/[email protected]

Add the following to the contents of the newly created file -

[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target

[Service]
Type=simple
User=someuser
Group=someuser
WorkingDirectory=/home/someuser

PIDFile=/home/someuser/.vnc/%H:590%i.pid
ExecStartPre=-/bin/sh -c "/usr/bin/vncserver -kill :%i > /dev/null 2>&1"
ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1920x1080 -localhost no :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Update the permissions of the newly created file with

$ sudo chmod +x /etc/systemd/system/[email protected]

Reload the daemons so that it can load the new VNC service -

$ sudo systemctl deamon-reload

Enable the VNC service so that it loads on boot -

sudo systemctl enable [email protected]

Kill any existing VNC servers and start the service -

$ vncserver -kill :*
$ sudo systemctl start vncserver@1

Check the status of the service with -

$ sudo systemctl status vncserver@1
  1. https://www.nodinrogers.com/post/2021-11-15-connecting-to-ubuntu-via-vnc-default-wm/
  2. https://askubuntu.com/questions/1159513/unable-to-connect-through-vnc
  3. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-22-04
  4. https://acloudguru.com/hands-on-labs/configuring-a-host-firewall-on-ubuntu-using-ufw
@elkuno213
Copy link

Thanks for this guide :) A little fix, it should be sudo systemctl daemon-reload instead

@Gredys
Copy link

Gredys commented Aug 7, 2024

Thanks for this guide :) A little fix, it should be sudo systemctl daemon-reload instead

It should be daemon-reexec actually

@jrbe228
Copy link

jrbe228 commented Sep 22, 2024

If you have issues running graphical apps like Firefox or Chromium, you can allow remote access to X11 from your VNC session by running the following:
xhost +local:

Then run the app as:
sudo dbus-launch firefox

@EIC-JayGanatra
Copy link

Thanks for the steps

Here I want to use the Queyconnect option but it dosen't work it says failed to open dialog box at local user. Do you have any idea regrading that ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment