Mounting msdos USB with permissions on OSX

20 Nov 2015 in TIL

This was a fun one. I have my SSH keys on an external disk, but OSX insisted on mounting it as 0777 which meant that SSH didn't want to read my keys. I couldn't use umask to change the mount permissions as it's an msdos USB stick.

Thanks to a combination of symlinks and bindfs, I have it working now.

How to fix:

bash
# Install bindfs
brew install homebrew/fuse/bindfs
# Write aliases to mount/unmount (in .zshrc for me)
unlock () {
bindfs -n -p 0700 -u $(id -u) -g $(id -g) /Volumes/DATASHUR ~/lockbox
echo "Unlocked"
}
lock () {
umount ~/lockbox
echo "Locked"
}
# Mount the fs
unlock
# Create my symlinks
ln -s /Users/michael/lockbox/keys/ssh .ssh
ln -s /Users/michael/lockbox/keys/ssh/.ssh-ident .ssh-ident
# Now it works!
$ ssh
Loading keys:
/Users/michael/.ssh/identities/personal/id_rsa
Enter passphrase for /Users/michael/.ssh/identities/personal/id_rsa: