Linux :: VNC

VNC

TigerVNC

initiate

pacman -Syu tigervnc
vncpasswd # set password at ~/.vnc/passwd

# Edit /etc/tigervnc/vncserver.users
# start with 1 because 0 is local display
    :1=username

# find available DE session
ls /usr/share/xsessions/*.desktop
# Edit [~/.vnc/config](https://tigervnc.org/doc/Xvnc.html)
    session=session-name
    geometry=1920x1080
    depth=24
    localhost # only allow localhost including SSH
    alwaysshared # new connection does not disconnect existing ones

# Start the server
systemctl start vncserver@:1

# to keep vncserver alive after log out
systemctl edit vncserver@
# edit /etc/systemd/system/vncserver@.service.d/override.conf
    [Service]
    Restart=on-success
    RestartSec=10

# Stop the server :1
systemctl stop vncserver@:1

# connect on client
vncviewer :1

# Short cut for SSH tunnel; [host]:[display#] or [host]::[port]
# This is equivelant to 
# ssh -fL 5901:localhost:5901 hostip sleep 10; vncviewer localhost:5901
vncviewer -via user@hostip localhost::5901

Local display :0

x0vncserver -rfbauth /path/to/pwd -display :0 -rfbport 5901 &> /dev/null & 

x11vnc

Start X11VNC before Xorg login

sudo x11vnc -rfbauth /home/usr/.vnc/passwd -auth /var/run/sddm/* -display :0

# Archwiki
x11vnc -display :0 -auth $(find /var/run/sddm/ -type f)

Connect VNC through SSH tunnel

# start ssh tunnel - localport and be any, remote port is VNC port nubmer
# -t force allocate pesudoterminal, improve interative typing
# -C enable compression - may slow things down
ssh -i /path/to/key -t -p SSHport -L localport:localhost:remoteport usr@ip

# start x11vnc
x11vnc -localhost -usepw -display :0

# together
ssh -i /path/to/key -t -p SSHport -L localport:localhost:remoteport usr@ip 'x11vnc -localhost -usepw -display :0'

# viewer - number corresponding to display in x11vnc
vncview localhost:0