Locally Mounting a Remote Directory Through a Firewall Gateway on OS X

  1. Download and install MacFUSE.
  2. Download the sshfs binary, renaming/moving to, for example, “/usr/local/bin/sshfs“.
  3. Create a wrapper tunneling script and save it to somewhere on your system path (e.g., “/usr/local/bin/ssh-tunnel-gateway.sh“), making sure to set the executable bit (“chmod a+x“):
    #! /bin/bash
    
    ssh -t GATEWAY.HOST.IP.ADDRESS ssh $@
    
  4. Create the following script, and save it to somewhere on your system path (e.g., “/usr/local/bin/mount-remote.sh“), making sure to set the executable bit (“chmod a+x“):
    #! /bin/bash
    
    SSHFS_PATH="/usr/local/bin/sshfs"
    SSH_TUNNEL_WRAPPER='ssh-tunnel-gateway.sh'
    
    REMOTE_HOST="FIREWALLED.HOST.IP.ADDRESS"
    if [[ -n $1 ]]
    then
        REMOTE_DIR="$1"
    else
        REMOTE_DIR=''
    fi
    if [[ -n $2 ]]
    then
        MOUNT_NAME="$2"
    else
        MOUNT_NAME="$REMOTE_HOST"
    fi
    LOCAL_MOUNT='/Volumes/'$MOUNT_NAME
    
    if test -d "$LOCAL_MOUNT"
    then
        echo "Mount point $LOCAL_MOUNT already exists."
    else
        echo "Creating mount point: $LOCAL_MOUNT"
        mkdir "$LOCAL_MOUNT"
    fi
    
    $SSHFS_PATH -o ssh_command=$SSH_TUNNEL_WRAPPER $REMOTE_HOST:$REMOTE_DIR $LOCAL_MOUNT -oreconnect,volname=$MOUNT_NAME -o local -o follow_symlinks
    
    if [[ $? == 0 ]]
    then
        echo "Mounted $REMOTE_HOST:$REMOTE_DIR at $LOCAL_MOUNT"
        echo "Use \"umount $LOCAL_MOUNT\" to unmount."
    fi
    
  5. And the fat lady sings …

Leave a Reply

Your email address will not be published. Required fields are marked *