# 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
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
# 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>