# TigerVNC - Website: [tigervnc.org](https://tigervnc.org/) - Github: [TigerVNC/tigervnc](https://github.com/TigerVNC/tigervnc) - [Founding announcement](https://www.mail-archive.com/[email protected]/msg27308.html) ## Install on Ubuntu 20.04 [[2021-03-26]] Adapted from: - (Primary source) [How to Install and Configure VNC on Ubuntu 20.04](https://linuxize.com/post/how-to-install-and-configure-vnc-on-ubuntu-20-04/) - (Secondary source) [How To - TigerVNC over SSH](https://forum.manjaro.org/t/root-tip-how-to-tigervnc-over-ssh/75087) ### (Optional) Use different desktop Install some alternative nice desktops, which will show up as a "session"later. **WARNING**: This takes a long time! ```bash sudo apt uninstall lubuntu-desktop ``` ### Install and configure VNC ```bash # Dependencies sudo apt update sudo apt install xfce4 xfce4-goodies # Install sudo apt install tigervnc-standalone-server # Password vncpasswd ``` ~~Configure to use Xfce. In `~/.vnc/xstartup`:~~ This might not be necessary. Only try it if later steps fail (and let me know if it was required!) ```text #!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS exec startxfce4 ``` Give execute permissions ```bash chmod u+x ~/.vnc/xstartup ``` Setup config file ```bash # List available sessions $ ls /usr/share/xsessions xfce.desktop # Edit config file vim ~/.vnc/config ``` `~/.vnc/config`: ```text session=<session> geometry=1280x720 localhost dpi=96 ``` - Fill in `<session>` from above, e.g. `xfco.desktop` Start the VNC server manually ```bash $ vncserver /usr/bin/xauth: file /home/ubuntu/.Xauthority does not exist New Xtigervnc server 'ubuntu:1 (ubuntu)' on port 5901 for display :1. Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/ubuntu/.vnc/passwd :1 to connect to the VNC server. ``` - *Note the `:1` after the [hostname](https://linuxize.com/post/how-to-change-hostname-on-ubuntu-20-04/) in the output above. This indicates the number of the display port on which the vnc server is running. In this example, the server is running on TCP port `5901` (5900+1). If you create a second instance with `vncserver` it will run on the next free port i.e `:2`, which means that the server is running on port `5902` (5900+2).* - *What is important to remember is that when working with VNC servers, :X is a display port that refers to 5900+X.* List all currently running VNC sessions ```bash vncserver -list ``` Stop the VNC instance ```bash vncserver -kill :1 Killing Xtigervnc process ID 5710... success! ``` ### Daemonize Edit `systemd` unit file. Requires root to save ```bash vim /etc/systemd/system/[email protected] ``` `/etc/systemd/system/[email protected]`: ```text [Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=simple User=<username> PAMName=login PIDFile=/home/%u/.vnc/%H%i.pid ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :' ExecStart=/usr/bin/vncserver :%i -geometry 1440x900 -alwaysshared -fg ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target ``` - Change `<username>` to machine user Notify systemd that a new unit file is created: ```bash sudo systemctl daemon-reload ``` Enable the service to start on boot: ```bash sudo systemctl enable vncserver@1 ``` Start the service ```bash sudo systemctl start vncserver@1 ``` Check on service status ```bash sudo systemctl status vncserver@1 ``` ### Setup controlling machine Install controlling driver ```bash brew install tiger-vnc ``` - May be `tigervnc` on Linux systems ### Connect VNC is an unencrypted protocol, so we want to use SSH tunneling. In one command, open the tunnel and connect using the tunnel: ```bash ssh -fL 5901:127.0.0.1:5901 \ [email protected] sleep 10; \ vncviewer 127.0.0.1:5901 ``` - In this `ubuntu` is the username and `192.168.1.8` is the remote ip. - Enter vncpassword when prompted, then machine user password. - Autoclosing SSH tunnel trick is from [this Stack Overflow answer](https://unix.stackexchange.com/a/83812/488417) ### Alternative connect workflow This was suggested by the primary article, but does not include autoclose of the SSH tunnel. Also, it's kind of finicky. Open the SSH tunnel ```bash # Variant 1 ssh -L 5901:127.0.0.1:5901 -N -f [email protected] # Variant 2 - try if above doesn't work ssh -fL -N 5901:127.0.0.1:5901 -l ubuntu 192.168.1.8 ``` - Note the addition of `-N` which keeps the SSH tunnel open. Open GUI ```bash vncviewer ``` Connect to `localhost:5901` ![[Pasted image 20220818012539.png]] If you need to kill the ssh process: ```bash ps | rg ssh kill <pid> ```