Alan Dipert

Saturday July 5, 2008
Category  

MacFUSE is an OS X kernel extension that can load usermode filesystem modules. One of the filesystems you can integrate directly into the Finder is really a pseudo filesystem: SSH. This is really handy especially since the Finder’s FTP functionality is limited to read-only. Most people who want to use the Finder or something like it for web work either buy Fetch, use Fugu, or opt for ftp, ncftp, or sftp on the command line. But MacFUSE is free, easy, secure, and rocks.

Once you have MacFUSE Core and the SSHFS application installed, you’re cooking. But how do you connect to and mount SSHFS volumes automatically?

Well, it turns out inside the sshfs.app application bundle, there’s a CLI flavor of the sshfs mounter. It’s located here:

/Applications/sshfs.app/Contents/Resources/sshfs-static-10.5

Steps for Beginners. Guru? Skip to 4

1. If you don’t already, it’s not a bad idea to take advantage of a /usr/local directory hierarchy for incidental or home-rolled command line binaries and jazz. We’re about to make a symlink to the sshfs-static-10.5 binary, and we need a spot to put the target. Below is a command which creates the specified directory as well as directories above it, as required, as instructed with the ‘p’ flag:

sudo mkdir -p /usr/local/bin

2. So now we have a spot for a symbolic link to the sshfs.app CLI that we can update in the future (for instance, for sshfs-static-10.6). We just need to add /usr/local/bin to the list of directories searched for executables. This line will do the trick:

export PATH=$PATH:/usr/local/bin

You can stick that in ~/.profile or ~/.bash_profile and it will be executed every time you open a shell.

3. I have a symbolic link from /usr/local/bin/sshfs to the above program, which I created with this line:

sudo ln -s /Applications/sshfs.app/Contents/Resources/sshfs-static-10.5 /usr/local/bin/sshfs

4. Now that we have an environment that knows about the command line version of sshfs, consider the following, an excerpt from my .bashrc:

#mount remote home directory
MOUNTPOINT=/Volumes/uberhome
REMOTE=alan@ubergibson.com:/home/alan
OPTIONS=-oping_diskarb,volname=uberhome
TESTHOST=ubergibson.com
#test if sshfs already mounted
if ! [ -e $MOUNTPOINT ]
then
        #test if connected to internet
        if ! [ -z "`ping -c 1 $TESTHOST 2>/dev/null | grep "time="`" ]
        then
                mkdir $MOUNTPOINT
                sshfs $REMOTE $MOUNTPOINT $OPTIONS
                echo "$REMOTE mounted on $MOUNTPOINT"
        else
                echo "Network down, unable to mount $REMOTE"
        fi
fi

The variable assignments are self-explanatory, and are unique to my setup.

The first if statement checks if the file /Volumes/uberhome exists with the -e flag. If it doesn’t exist, meaning the volume has not yet been mounted, move on to the next test.

The next test tries to ping ubergibson.com. Successful runs of ping always result in output that contains the string “time=”, so we grep for it. The -z flag tests the result of the ping/grep for whether or not it is null. If it isn’t, mkdir a mount point and run sshfs. Then, say it worked.

My script gets run every time I open a shell. There are fancier ways of going about automounting, like customizing your login and logout with scripts and applications

There are a billion ways to skin a cat. But I hope you have fun with this one. Happy computations.

Comment

  1. xanax [url=“http://www.forgetanxiety.com/”]xanax[/url] http://www.forgetanxiety.com/ 4120

    Tabellengitternetz · Jan 11, 01:48 PM · #

  2. ALUTaoo

    LBapcSW · Feb 2, 10:03 PM · #

  3. XoTQemNl

    lNAngqH · Feb 2, 10:22 PM · #

  4. yFuKAEMy

    KzjsDL · Feb 18, 12:14 PM · #

  5. aMDtIA ldadnkxjfmwx, [url=http://oscesvpyaifp.com/]oscesvpyaifp[/url], [link=http://vzidajxzqwlh.com/]vzidajxzqwlh[/link], http://cerfxerownjl.com/

    moqhdd · Mar 5, 03:35 PM · #

  6. cPVCYsJ

    CizRKzDm · Mar 9, 08:35 AM · #

  7. mXKvcLu

    ZTGHwdfR · Mar 9, 03:41 PM · #