Monday, November 23, 2009

VNC through SSH tunnel

At work, I often use two computers, and to avoid moving back and forth with the keyboard and the mouse, I have both computers sharing one keyboard and mouse via synergy. I've even written a short article on how to get it working.

But even that has become a bit annoying because I still have to move my head between the display of one computer, and another. So, I decided to share my X session with VNC and just use my secondary machine on a VNC session.

To try to improve security a bit, I decided to tunnel my VNC connection via ssh using this article. The only thing about the article that I would point out is when starting the ssh tunnel, use the -X (or -Y) option so the vnc client can use the X display.

Linux VNC server setup

Log into your Linux host box.
[bar]$ ssh foo

[foo]$ vncpasswd

Only set this vnc password once. You'll need it to connect from any remote or local client

[foo]$ vncserver -localhost

Do not omit the -localhost argument, this stops VNC from listening on the external interface. IMPORTANT Note the server number returned by vncserver after you launch it. You will need this number to kill the server and to configure the SSH client.

[foo]$ exit

Linux client

From your local linux desktop open an ssh session
[bar]$ ssh -X -L 5901:localhost:590n foo

Note that n is your server number. Above command connects you to foo with a tunneled port as well.

[foo]$ vncviewer localhost:n


I guess it never hurts to remind fedora users, that the VNC packages are called: tigervnc and
tigervnc-server.