User Tools

Site Tools


vnc_over_ssh

Using VNC Over SSH

Setting it up for the first time

  • Install vncserver on the destination machine.
  • Run vncserver once and note the session number given (:1 if nobody else is using VNC on the machine). It will ask you to create a vnc password so do so. Example (minus the password part):
[adam@host ~]$ vncserver

New 'host.remotemachine.co.uk:1 (adam)' desktop is host.remotemachine.co.uk:1

Starting applications specified in /home/adam/.vnc/xstartup
Log file is /home/adam/.vnc/host.remotemachine.co.uk:1.log

(Note, if another VNC session is already running on the target machine, your session might :2, :3 or :x, where x is the number of your session as shown above).

  • Kill the vncserver, with:
vncserver -kill :1

where :1 is your session ID.

  • Now go into your ~/.vnc directory while on the remote machine and edit the xstartup file
  • Comment out the xterm and twm lines and place:
gnome-session &

at the bottom. Now log out.

Of course the Gnome Desktop environment needs to be installed for this to work.

Using VNC over SSH for real

Now that all the background stuff is done, you can use it for real.

  • On your local machine start an SSH redirection over the VNC ports to the destination machine as follows:
[adam@localhost ~]$   ssh -C -L 5901:127.0.0.1:5901 <username>@<remotemachine>

(Note, if another VNC session is already running on the target machine, then the second 5901 needs to be 590x, where x is the number of your session as shown in the first section).

This creates a port redirection from the VNC port on your local machine to the VNC port on the remote machine, using SSH as an encrypted tunnel and gives you an SSH shell. Ignore the SSH shell for now, or use it as you need, but don't log out of it until you're finished with your VNC connection.

  • Start vncserver in your SSH shell as above and note the session ID.
  • To connect using a VNC client, tell your client to connect to localhost:x, 127.0.0.1:x, localhost:590x or 127.0.0.1:590x, where where x is your VNC session ID. Some clients are funny about whether your specify 127.0.0.1 or localhost and x or 590x, so one of these combinations will work.
  • To end your VNC session, just close the VNC window.
  • To close the vncserver, just do vncserver -kill :x as explained above. You can leave it running if you're likely to reconnect to it later and you're confident in the security of your password.
  • To kill the port redirection, just logout of the SSH shell.
vnc_over_ssh.txt · Last modified: 2016/11/25 22:38 (external edit)