Skip to Content

Mounting remote drives locally using sshfs

To mount a network drive as a local one, you can use sshfs.

Generate SSH key

$ mkdir ~/.ssh #if it does not already exist
$ chmod 700 ~/.ssh
$ cd ~/.ssh
$ ssh-keygen -t rsa
$ enter a keyname
$ enter a passphrase
$ ssh-copy-id -i [path to rsa file] USER@SERVER

Where -i indicates where the rsa file is located. The .pub key is the one needed to be copied.

[Optional] Start a SSH agent, and add the key to the SSH agent:

$ eval `ssh-agent -s` # if needed
$ ssh-add ~/.ssh/KEY.pub

Install sshfs

For Ubuntu:

sudo apt install sshfs

For Mac:
Download both FUSE and SSHFS from here

Create a mounting point

# Ubuntu
sudo mkdir /mnt/foo

# Mac
sudo mkdir /Volumes/foo

Connect to the remove server

# Ubuntu
sudo sshfs USER@SERVER:/ /mnt/foo/ -o allow_other,IdentityFile=/home/USER/.ssh/SERVER_rsa

# Mac
sudo sshfs USER@SERVER:/ /Volumes/foo/ -o allow_other,IdentityFile=/home/USER/.ssh/SERVER_rsa,defer_permissions

Disconnect from the remove server

# Ubuntu
sudo umount /mnt/foo

# Mac
sudo umount /Volumes/foo