VNC made easy

there are many options how to log into your computer from somewhere else via VNC (for example you are at home and want to check the computer in the office). the following requires x11vnc to be installed on the office computer and vncviewer on the home computer. also, you need to run

1
x11vnc -storepasswd

on your office computer to choose a password that you will need to enter in order to connect to this vnc server.

if you then launch the following script on your home computer, it tunnels via ssh into your office computer and starts the VNC server. 10 seconds later, a second terminal opens which launches the vncviewer on your home computer. make sure you enter the ssh password in the first terminal quickly so that the vnc server is started before vncviewer tries to connect to it. the password in the first terminal is your ssh password, the one in the second terminal is the x11vnc password you set earlier.

obviously, you need to replace <username> and <computername> with the appropriate values.

1
2
3
4
5
#!/usr/bin/env bash
 
gnome-terminal -e "ssh -t -L 5900:localhost:5900 <username>@<computername> 'x11vnc -usepw -scale 0.6 -ncache 0 -localhost -display :0'" &
sleep 10
gnome-terminal -e "vncviewer -encodings 'copyrect tight zrle hextile' localhost:0" &

Leave a Reply