Mounting a Remote Directory through a Gateway using MacFUSE
A firewalled-server that restricts access only through a gateway machine is a reasonable security measure, but it is a pain to have to hop through the gateway everytime you need to transfer files. It also makes it difficult to use local applications to work directly on files on the firewalled server, even if the applications support ssh- and ssftp-based editing protocols. Using a FUSE (Filesystem in Userspace) approach, you can mount a remote directory on a firewalled-server as a local volume (or directory), resulting in seamless and hassle-free access. MacFUSE is a great addition to the OS X system, and, with this, FUSE-based access to a firewalled server is a much simpler alternative to ssh tunnelling.
So, here is the recipe on how to mount a remote directory through a gateway:
- You will, of course, need to be authorized to access both the gateway (from your local machine) and the server (from the gateway). However, you will also need to set up ssh for passwordless access in both cases (i.e., so that you can ssh from your local machine to the gateway, and from the gateway to the server without being prompted for logins.) This is not difficult to do, and if you google for "ssh passwordless login" you will find a ton of information.
- Download and install both MacFUSE and sshfs (get the latest versions for your operating system from the project's home page at http://code.google.com/p/macfuse/).
-
Create a convenient link to the statically-compiled command-line binary on your system path:
sudo ln -s /Applications/sshfs.app/Contents/Resources/sshfs-static /usr/bin/sshfs
At this point, mounting a remote directory using the ssh protocol itself is fairly straightforward:sshfs user@host:/some/directory /some/mount/point -oreconnect,volname=
whereis the name to be given to the mounted volume. This protocol, though, does not allow access to a firewalled server. To do this, we will need to connect to the firewalled server through the gateway, and we need to wrap up this access in a way that makes it easy to pass tosshfs. -
Save the following wrapper script as "/usr/bin/gateway-ssh", setting a+x permissions:
#! /bin/sh ssh
wheressh $@ is the address of the gateway host. -
Now simply use the
"-o ssh_command="option ofsshfs:sshfs -o ssh_command="/usr/bin/gateway-ssh"
where@ :/home/ /path/to/mount/dir -oreconnect,volname= andis the address and your login, respectively, to the firewalled server. And that's it! It does not pop up on your desktop, but you can see it if you open your computer. You could use the"-o local"option for more Finder-friendly behavior:sshfs -o ssh_command="/usr/bin/gateway-ssh"
@ :/home/ /path/to/mount/dir -oreconnect,volname= -o local -
To unmount:
umount /path/to/mount/dir
feed
Post new comment