Mounting msdos USB with permissions on OSX

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:

# 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

# 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:
Enter passphrase for /Users/michael/.ssh/identities/personal/id_rsa:

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply