Skip to content

Instantly share code, notes, and snippets.

@LakithKarunaratne
Created November 3, 2021 06:33
Show Gist options
  • Save LakithKarunaratne/e4ce2c906f98f41c65e86e05ff468e4c to your computer and use it in GitHub Desktop.
Save LakithKarunaratne/e4ce2c906f98f41c65e86e05ff468e4c to your computer and use it in GitHub Desktop.
Setup TigerVNC for ubuntu

Install

sudo apt install tigervnc-standalone-server

first run and set password

vncserver

Enter n for view only mode

to change password

vncpasswd

Configure the server

Kill active instance vncserver -kill :1

Create new file if not present nano ~/.vnc/xstartup

#!/bin/sh
# Start Gnome 3 Desktop
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

Set as executable chmod +x ~/.vnc/xstartup

Restart server as insecure vncserver -localhost no :1

Connect with any VNC client hostname|ipaddress:5901

Once verified kill insecure session vncserver -kill :1

Secure Connection

On the guest machine you need ssh setup and installed.

Create a ssh tunnel ssh -L 59000:localhost:5901 -C -N -l server_user_name server_ip_address add -f flag to run in the background

Connect with any VNC client to tunneled local port localhost:59000

This might give warning as insecure, ignore it as the local port is tunneled via ssh.

Create systemd service

Create unit file in the host system sudo nano /etc/systemd/system/vncserver@.service

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

[Service]
Type=forking
User=YOUR_USERNAME	# change as needed
Group=YOUR_USERNAME	# change as needed
WorkingDirectory=/home/YOUR_USERNAME	# change here

PIDFile=/home/YOUR_USERNAME/.vnc/%H:%i.pid	# change here
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i	# set resolution if needed
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Kill any exisiting vnc sessions vncserver -kill :1

Enable and restrart the systemd

sudo systemctl enable vncserver@1.service
sudo systemctl daemon-reload

Start the vncserver with systemd sudo systemctl start vncserver@1

Check status with sudo systemctl status vncserver@1

Source Material

bytexd.com

@LakithKarunaratne
Copy link
Author

Might show blank screen for some, check configuration for xstartup and make changes there

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