This post will show you how to mount a remote ssh filesystem as a ‘drive’ in osx using a bash script, osxfuse and brew. There are a few ways to go about this, all of them require a bit of setup and tweaking, But I found this to be the easiest way – once its setup you don’t need to do anything, and you have a command to re-mount the drive if need be.

osx remote sshfs filesystem

Things you need before you begin

1) you need to install osxfuse if you dont already have it [ http://osxfuse.github.io ]
2) you also need to install homebrew [ http://brew.sh ]
3) once you have brew you need to install ssh-copy-id and sshfs from homebrew


brew install sshfs ssh-copy-id

4) setup keyless authentication [ /ssh-with-keys-for-authentication ]

sshfs mount remote drive

To do this we will create a script to mount the drive for us (we can run this script at any time to mount the drive – eg if you get a disconnection just re-run this script and the drive will re-mount)

vi ~/bin/mount_remote_drive

# I made this in my ~/bin folder - remember to chmod +x the file after you make it

# give your drive a nice name and location
mkdir /Volumes/SomeNiceName

#mount it
sshfs -o reconnect -o volname=SomeNiceName -o IdentityFile=~/.ssh/id_rsa remotehost.com:/path/to/wherever /Volumes/SomeNiceName

The options used:
-o reconnect — this will re-mount the drive after you suspend your computer, etc
-o volname=SomeNiceName — this will show ‘SomeNiceName’ as the label of your drive
-o IdentityFile — this is the location of your ssh key so you dont have to enter a password all the time

You can now run this script in a terminal to mount your drive

~/bin/mount_remote_drive

you’ll see a nice little drive icon on your desktop which you can use in finder like any other folder :D

Launch that script at login

The easiest way to do this is via your startup items – that way every time you log in your drive will mount:

  • open system prefs > users & groups > your user > login items
  • click the + in the bottom corner
  • browse to the script you just made
  • click ok