Skip to content

Instantly share code, notes, and snippets.

@Birch-san Birch-san/sshfs_mount.sh

Last active Oct 27, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.