Skip to content

Instantly share code, notes, and snippets.

@elkuno213
Last active April 6, 2024 04:52
Show Gist options
  • Save elkuno213/4eb921b320c7a8c53ba72ec24e0b48b3 to your computer and use it in GitHub Desktop.
Save elkuno213/4eb921b320c7a8c53ba72ec24e0b48b3 to your computer and use it in GitHub Desktop.
TigerVNC remote setup in Ubuntu

TigerVNC server

# 1. Type 2 times password to access.
# 2. Type 'n' for view-only password
git clone https://gist.github.com/4eb921b320c7a8c53ba72ec24e0b48b3.git /tmp/vnc-remote-setup
sudo chmod +x /tmp/vnc-remote-setup/install_tigervnc_server.sh
/tmp/vnc-remote-setup/install_tigervnc_server.sh
sudo rm -rf /tmp/vnc-remote-setup

TigerVNC client

Installation

git clone https://gist.github.com/4eb921b320c7a8c53ba72ec24e0b48b3.git /tmp/vnc-remote-setup
sudo chmod +x /tmp/vnc-remote-setup/install_tigervnc_client.sh
/tmp/vnc-remote-setup/install_tigervnc_client.sh
sudo rm -rf /tmp/vnc-remote-setup

Configuration

# Copy passwd from server to client for ssh passwordless
scp -rp <server-username>@<server-ip>:/home/<server-username>/.vnc/passwd $HOME/.vnc/passwd.<server-username>

# Connect from client by:
# 1. Use vncviewer directly
vncviewer localhost::5901 -via <server-username>@<server-ip> -passwd $HOME/.vnc/passwd.<server-username>
# 2. Add ssh config and use it for vncviewer
echo '
Host <server-name>
  HostName <server-ip>
  User <server-username>
  ForwardX11 yes
  ForwardX11Trusted yes
  LocalForward 5901 localhost:5901
' >> $HOME/.ssh/config
vncviewer localhost::5901 -via <server-name> -passwd $HOME/.vnc/passwd.<server-username>
# 3. Run ssh tunnel in background and use it for vncviewer
# `-f` run ssh in background
# `-N` do not execute a remote command (shell)
ssh -Y -f -N -L 5901:localhost:5901 <server-username>@<server-ip> # ssh tunnel
vncviewer localhost::5901 -passwd $HOME/.vnc/passwd.<server-username>
#!/bin/sh
# Installation
sudo apt-get -y install tigervnc-viewer
#!/bin/sh
# Prerequisites: install sudo before running this script
# Get the directory containing the script
script_dir=$(dirname "$0")
# Installation
sudo apt-get -y update
sudo apt-get -y install xfce4 xfce4-goodies
sudo apt-get -y install tigervnc-standalone-server
vncserver
# Configuration of xfce4
cp $script_dir/xstartup.xfce $HOME/.vnc/xstartup
sudo chmod +x $HOME/.vnc/xstartup
# Setup vncserver service
sudo cp $script_dir/vncserver@.service.template /etc/systemd/system/vncserver@.service
sudo sed -i "s/someuser/$(whoami)/g" /etc/systemd/system/vncserver@.service
sudo chmod +x /etc/systemd/system/vncserver@.service
sudo systemctl daemon-reload # make system aware of new unit file
sudo systemctl enable vncserver@1.service # enable unit file
vncserver -kill :* # kill all vncserver instances
sudo systemctl start vncserver@1
# sudo systemctl status vncserver@1
[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
#!/bin/sh
# Start up the standard system desktop
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/usr/bin/startxfce4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment