During this pandemic I’m working from home on my Mac laptop and accessing things on my Ubuntu 18.04-based Linux desktop in the office. For most things this is fine via SSH or sshfs, but there are times you just need access to the desktop UI to get things done.
Specifically I had a 500 MB OVA that I needed to upload to an ESXi system — both of which are in the office. I could have downloaded the OVA to my laptop over the VPN, then uploaded it back over the VPN to ESXi but that is both slow, tedious, and wasteful. Instead after a bit of googling I figured out how to get a VNC client on my Mac securely accessing my work Xwindows display and do it all local to the office:
On your desktop, install x11vnc:
sudo apt install x11vnc
On your home computer, open an SSH tunnel and start the viewer on your remote system (below as $HOSTNAME):
ssh -t -L 5900:localhost:5900 $HOSTNAME 'x11vnc -localhost -display :0'
Then start a VNC viewer on your home computer (on MacOS I recommend RealVNC) and connect to localhost:5900
Security advisory: when accessing your desktop like this your computer is unlocked and accessible by keyboard and mouse to users who wander by your desk. Granted, in a pandemic when everyone is working from home is this really a problem? Lock your computer when you’re done as if you were walking away from your desk and you’ll be fine.