Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.6 Shell Script and AppleScript (SSH tunnel for VNC)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6 Shell Script and AppleScript (SSH tunnel for VNC)
Authored by: Rainy Day on Apr 05, '11 02:02:58PM
This works from the Bash shell:
ssh username@example.com -fL6900:127.0.0.1:5900 -o ExitOnForwardFailure=yes sleep 45 && killall ssh-agent; open -W vnc://screen.example.com:6900
Where "username" should be replaced by a username on the remote machine, and "example.com" is the remote’s domain name or IP address. "screen.example.com" can be either 127.0.0.1, or a pseudo domain name you've defined in your /etc/hosts file (which makes it easier for humans to read).

The choice of internal port 6900 was arbitrary; any unused internal port may be used.

The optional "killall ssh-agent;" is used to remove an ssh keychain helper (which is sometimes launched when the tunnel is established).

This ssh tunnel collapses when you close the Screen Sharing app (provided the tunnel has been open longer than the number of seconds specified in the sleep parameter).

This all can be easily wrapped inside an AppleScript and made conveniently available via the AppleScript Menulet:

do shell script "/usr/bin/ssh username@example.com -fL6900:127.0.0.1:5900 -o ExitOnForwardFailure=yes sleep 45 && killall ssh-agent; open -W vnc://screen.example.com:6900"
This was tested under Snow Leopard.

Use it in good health!

Edited on Apr 06, '11 03:03:11PM by Rainy Day


[ Reply to This | # ]
Deleted comment
Authored by: Rainy Day on Apr 06, '11 01:55:45PM

Deleted.

Edited on Apr 06, '11 03:04:48PM by Rainy Day



[ Reply to This | # ]
Targeting a third machine
Authored by: Rainy Day on Feb 17, '13 12:11:15AM
Note: If you wish to establish the tunnel to one machine on a remote LAN, but target another machine on that same LAN for screen sharing, then replace 127.0.0.1 in the ssh command with the third (target) machine's IP address. For example, if the third machine's s IP address is 192.168.0.32, the command would look something like this:
do shell script "/usr/bin/ssh username@example.com -fL6900:192.168.0.32:5900 -o ExitOnForwardFailure=yes sleep 45 && killall ssh-agent; open -W vnc://screen.example.com:6900"
This was tested under Mountain Lion.

[ Reply to This | # ]