Monday, 11 August 2014

3 useful tunnelling scripts for mac - SSH, VNC and AFP

I just thought I'd share these three scripts. I have previously blogged about setting up a tunnel, but I've had some people asking for these scripts specifically. The first sets up a permanent tunnel and changes location to one called Proxied - so you'll need to set this up. See my earlier post for details on this.

#! /bin/bash

handleSigint()
{
  echo SIGINT detected - reverting Location...
  scselect "Automatic"
  exit 0;
}

trap handleSigint SIGINT

scselect "Proxied"

sleep 5;

while [ 1 ]; do
  ssh -v -N -D8080 -o ServerAliveInterval=3 user@mydomain.com
  echo ssh exited... relaunching...
  sleep 5

done

Note that you'll need to change user@mydomain.com.

This script improves slightly on the original, as it catches CTRL-C and sets the location back to "Automatic".

Here's the next script - fires up screen sharing / VNC on a machine on my home network:

#! /bin/bash

echo Connecting...
ssh -f -v -N -L5900:192.168.0.11:5900 \
  -o ServerAliveInterval=3 user@mydomain.com
sleep 2; # Allow connection setup time

open vnc://localhost

Note that the 192.168.0.11 should be the machine on your network you want to connect to - note the use of the private network 192.168 here. This is the IP address my iMac at home as been assigned. Don't forget to change user@mydomain.com again.

Finally, here's a new one - this allows you to 'mount' drives from a machine on your home network. It's very similar to the VNC script, but binds the AFP port, not the VNC one:

#! /bin/bash

echo Connecting...
ssh -f -v -N -L15548:192.168.0.11:548 \
  -o ServerAliveInterval=3 user@mydomain.com
sleep 2; # Allow connection setup time

open afp://localhost:15548/

I've used a non standard port for this one to avoid conflicting with any local services you may have on this port.

You can share any service in exactly this same way - as long as you know the port number.

Enjoy!

No comments:

Post a Comment