Skip to content

Instantly share code, notes, and snippets.

@Birch-san
Last active October 27, 2018 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Birch-san/9c8f971e7c5a2b997ca93ffd5c00765e to your computer and use it in GitHub Desktop.
Save Birch-san/9c8f971e7c5a2b997ca93ffd5c00765e to your computer and use it in GitHub Desktop.
How to use OSXFUSE + SSHFS to mount/unmount a remote filesystem
#!/bin/sh
# mounts a host named 'mycoolhost' (as described in SSH config):
# ./sshfs_mount.sh
# unmount:
# ./sshfs_mount.sh 0
REMOTE_HOST='mycoolhost'
REMOTE_DIR='/home/mycooluser'
VOLNAME="$REMOTE_HOST"
LOCAL_DIR="$HOME/mnt/$VOLNAME"
BIND="$REMOTE_HOST:$REMOTE_DIR"
mkdir -p "$LOCAL_DIR"
if [ "$1" == "0" ]; then
echo "unmounting '$VOLNAME'..."
umount "$BIND"
else
if mount | grep -q "^$BIND"; then
echo "'$VOLNAME' already mounted:"
mount | grep "^$BIND"
else
echo "mounting '$VOLNAME'..."
/usr/local/bin/sshfs "$BIND" "$LOCAL_DIR" -ovolname="$VOLNAME"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment