Nextpertise a journal of interesting technical ideas . . .

SSHFS Automount

by Brent Stewart on Saturday, Oct 17, 2020

I described using SSHFS as an alternative to NFS back in Using SSH3. I’ve been using SSHFS as a standard way to mount since then, partly because I can use the same technique on a variety of OS and partly because it seems to work cleaner for me than straight NFS. However, I’ve been using a batch file to mount drives and that’s getting old. I’d like to just add the SSHFS targets into /etc/fstab and get them to automount. As a general rule, the Arch Wiki is a great place to find all things Linux. Even though I’m running an Ubuntu variant, the Arch Wiki set me straight. For this to work there are a number of things that have to be set. First, as described in Using SSH2 I need to make sure that logging into my target is done with keys so that an interactive password is not required. See the previous article for a more detailed walk through, but the basic process is:

ssh-keygen  
ssh-copy-id brent@192.168.1.1

test

ssh brent@192.168.1.1

Second, edit /etc/fuse.conf to allow non-root users to access drives when they’re mounted with the allowother option.

sudo nano /etc/fuse.conf
# add or uncomment the following line
user_allow_other

Find out your user id and group id. This is easy: there’s an id username command. Note that the ellipsis below just indicate that I’m in other groups and I’ve edited those out.

➜ id brent
uid=1000(brent) gid=1000(brent)** ...

Finally, add the targets to your etc/fstab.

sudo nano /etc/fstab  
sshfs#brent@192.168.1.1:/home /home/remote fuse user,_netdev,
 reconnect,uid=UID,gid=GID,idmap=user,allow_other 0 0

When you exit nano the remote directory should be mounted and active! It will also be there automatically each time you log back in. Hope this is helpful!



References:
  https://wiki.archlinux.org/index.php/SSHFS

Recent articles related to these tags:
SSH Linux
Share this article:   
Tweet