Accessing remote computers via SSH with Finder
As a long time linux user, I have been familiar with FUSE or File Systems in Userspace as a way to access file systems that have traditionally been either unsupported on the platform or not file systems at all such as youtube or SSH. Recently I decided to attempt to do the same thing on OS X. What I found was a project called macFUSE. macFUSE lets you use FUSE file system drivers on the OS X operating system.
Installing macFUSE is very easy. Simply download the disk image provided here and install the package. It places a preference pane in your control panel and checks itself for updates. However macFUSE by itself is worthless. You need to have filesystem drivers that use macFUSE to do anything interesting with it. I should note that these drivers are not drivers in the Microsoft Windows sense, but simply just applications that use the macFUSE library. My main purpose for this was to be able to mount SSH connections as volumes in finder. So I will be explaining how to setup and use the SSH Filesystem for macFUSE. Please not there are tons of other filesystems out there for macFUSE such as ntfs (great for you windows users), youtube, or spotlight.
Installing and using the SSH Filesystem
The first step is to download the SSH filesystem application from the macFUSE website. It can be downloaded from here. You will want to download the file called sshfs-static-leopard.gz if you are using OS X 10.5 (leopard). Now extract the file inside and rename it to say simply sshfs. Now for the tricky part. We are going to need to use the terminal. Launch the terminal and check if the directory /usr/local/bin exists. To do this simply enter this command
ls /usr/local
You should see output that appears as follows:
Last login: Thu May 14 23:16:47 on ttys000 myMac:~ user$ ls /usr/local bin include lib myMac:~ user$
Notice the “bin” in the list. If you do not see the bin folder then you will need to create it. You can do that by running the following commands in the terminal:
sudo mkdir /usr/local/bin sudo chown root:wheel /usr/local/bin sudo chmod 755 /usr/local/bin
What this is doing is creating the new folder, setting the correct ownership, and finally setting the correct permissions. These commands are using sudo, which means they are admin commands and will require your password. I would take this time to point out that it is never a good idea to run commands on the terminal you do not understand. So it may be in your interest to do some research, although I can tell you these commands should be very safe.
Now that we have created the folder, we simply need to move our application into the folder and give it the correct ownership and permissions. We do that with these commands:
sudo mv /Users//Desktop/sshfs /usr/local/bin/ sudo chown root:wheel /usr/local/bin/sshfs sudo chmod 755 /usr/local/bin/sshfs
That is it! Now we can use sshfs to mount ssh connections as volumes (read folders) in Finder. Unfortunately sshfs is not a graphical application. This means the initial connection will require you to use a terminal. To use sshfs we do something that is called mounting. When you mount a filesystem you are taking an empty folder and telling the operating system to use the target (another drive or computer) as the contents of that folder. The steps of mounting a file system are as follows:
- Create a folder to use as a mount point or select a previous and empty folder
- Run the commands to mount the filesystem
- Use the filesystem as normal either via the terminal or Finder
- When finished, unmount the filesystem
Let’s go though these steps. First you need to create a mount point. The best way to do this is to open Finder and create a new folder inside your home folder. Name it something sensible. For example if I am going to mount my home server via ssh I would create a folder called sshHomeServer.
Now that the folder is created, we need to mount the filesystem. We do this with the following command:
sshfs username@192.168.1.100:/home/username -p 22 '/Users/username/sshHomeServer/' -oauto_cache,reconnect,volname="My Linux Server"
Now I know this command looks very complicated, but we are going to break it down. First you have “sshfs” this is the command we are running and tells macFUSE that we are mounting a ssh filesystem. Next we have “username@192.168.1.100:/home/username”. Here we would replace username with our username on the remote computer. So if my username was fred, then my command would be fred@192.168.1.100:/home/fred. One more thing about this section of the command, the :/home/fred part is the folder on the remote server we want to mount. So if we wanted to mount the music folder located at /Music/iTunes, we would use the command fred@192.168.1.100:/Music/iTunes. After this we have “-p 22″. This tells sshfs what port to use for the connection. Port 22 is the default for ssh. If you are using ssh on port 22 you can omit this part of the command. Next we have “‘/Users/username/sshHomeServer/’”. Again here you will replace username with your username on the local computer (the machine you are sitting at). What you are doing is telling the command the folder you want to mount the remote system at (aka the Folder you created on step one). Finally we have our options. These are standard and you shouldn’t need to change them with the exception of volname. Volname controls the name that will show up in finder and your desktop. So if you call it “My Linux Server”, you will get a disk on your desktop and in finder that says “My Linux Server”. If you want to know more about the options, simply type “sshfs -h” in a terminal window.
If the previous command was successful it will ask you for your password on the remote server. If you give the correct password you should have a new volume appear in Finder. This is exactly like what happens if you connect to a computer via smb or afp. If you would like the icon to appear on your desktop, you will need to edit the preferences in finder and check “Connected Servers” under “Show these items on the desktop” on the general tab. You can now use this folder exactly like you would a USB disk or network drive.
The final step is to unmount the volume after you are finished with it. This can be done a few ways. If the icon is on your desktop, you can drag it to the trash. If it is in finder, you can click on eject. Finally, if you are in a terminal you can type
umount /Users/username/foldername
Replacing username with your username and foldername with the name of the mount point.
Making it easier
While using the terminal is not very complicated and should be encouraged, sometimes you just don’t feel like using it. If you are like many people I know, you are asking yourself “Why hasn’t anyone written a graphical application to do this for us?” The answer is that there are some. I will get to those momentarily. Before I do however, I want to show you the quick and dirty application I wrote to automate this using AppleScript. I am doing this to show you the control and power you can leverage with ApplesScript.
So what is AppleScript? Well AppleScript is an object-oriented scripting language with a syntax resembling ordinary English. You can use it to automate repetitive tasks in applications, the Finder, and other parts of Mac OS X. Many OS X applications have hooks into applescript. That means you can write scripts to control iTunes, resize photos, run text commands in the terminal, search your email, or even check websites and download files. AppleScripts can also access the Cocoa framework which is what OS X uses to create graphical displays. This means your scripts can look and function like full fledge applications.
So knowing this I used AppleScript to create an application called SSHFS Control. You can download the application for intel macs running OS X 10.5 here: SSHFS Control. The icon was not created by me and as far as I can tell is part of the macFUSE sshfs project and licensed under the BSD license. If I am wrong please feel free to correct me. My code is licensed under the GPL v2. So feel free to take it and modify it as you see fit (as long as you comply with the terms of the GPL). The source can be found here: SSHFS Control Source Code.
Here are a few screenshots of the application in action.
Now I created this application simply as an exercise in what can be done quickly with AppleScript. This took me about 20 minutes to create not counting my breaks to post on Facebook and browsing StumbleUpon. If you are looking for a full featured well engineered solution. Keep reading
.
MacFusion, the graphical interface for MacFUSE
This is the solution you are looking for when it comes to a graphical interface for macFUSE. You can find MacFusion at http://www.macfusionapp.org/. As you can see from the screenshots on their website, MacFusion provides a wonderful interface for mounting, unmounting, and even saving and bookmarking your macFUSE filesystems. If you need a robust graphical solution this is it. MacFusion supports SSH and FTP by default. But it has a full plugin interface, so it is possible to create support for any filesystem that MacFUSE supports. I highly recommend it.
I hope this helps you use macFUSE. When searching for tutorials today I was unable to find any that used a recent version of macFUSE after they removed their experimental GUI for SSHFS. I think this will help fill that void. If anyone knows of any other great graphical interfaces to macFUSE I would love to hear about it!



