This is a simple way to mount an OSX shared folder over SSH without installing any additional software. For this to work you must be sharing a folder using AFP (Apple File Sharing) protocol and have “Remote Login” (i.e. SSH) enabled. These settings are all found in System Preferences->Sharing. If your server is behind a firewall, you must open the SSH port (usually port 22).
Step One: Open up terminal and enter the following command:
ssh -N -p 22 USERNAME@HOSTNAME -L 5480/localhost/548
Replace USERNAME with the remote username and replace HOSTNAME with the domain name or IP address of your server. For example jason@192.168.1.100. If you run SSH on a non-standard port, you can also replace 22 with your port number. You’ll be prompted for a password then you won’t see any further output.
This creates an SSH tunnel from local port 5480 to remote port 548. In Apple terms you might think of this as an alias. The remote server’s incoming port 548 is the default port used by Apple File Sharing service. Our local outgoing port 5480, on the other hand, is just an open port that is not known to be used by any common service. The outgoing port is not actually important, but these instructions assume you’re using 5480. Anyway, you might think of your tunnel as something like this:
local port 5480 -> SSH -> Internet -> SSH -> remote port 548
Step Two: Click anywhere on your desktop or open Finder so that you see the “Go” menu in your menu bar. Select from the menu bar: Go-> Connect to Server…
In the server address, enter “afp://localhost:5480″ (without the quotes)
This may seem crazy because it appears you are connecting to “localhost” which would normally be your local computer. Remember, though, the SSH tunnel connects local port 5480 to remote port 548. So we are actually connecting to port 548 on the remote machine.
After a moment you should get a standard login dialog. Enter your remote username/password and you’ll be presented with the available shares. Select the share you want and you should see it appear in the Finder in a moment. That’s it! You can now open and drag/drop files. The connection will probably be slower depending on your connection speed, but otherwise it works the same as if you were connecting directly.
(Optional) Additional Software and Alternatives
If you’re uncomfortable with the command like, there’s a GUI application for connecting to SSH servers and creating tunnels called SSH Tunnel Manager. You can download it from http://projects.tynsoe.org/en/stm/. The functionality is the same, but if you prefer clicking a button instead of typing in the terminal window, it can be useful.
Another method for connecting to shares over SSH is through an application called MacFuse with it’s required counterpart sshfs. This may look the same as an SSH tunnel, but is technically very different. MacFuse is a program that allows you to make anything appear to be a file system and SSH is just one of the possible implementations. You might say that this app tricks your computer into thinking something is a local hard drive. I gave MacFuse a try and personally did not find it reliable. A plain old SSH tunnel works great for me so I don’t plan to use MacFuse for this purpose. However it is an interesting idea and has many other uses.
Please feel free to leave a comment if you have any remote connection tips or tricks.