One of the most irrational things on Linux, when they don’t have to deal with Windows, it why use SAMBA/CIFS.

It’s cumbersome to configure, and don’t feel at home on Linux at all. And there’s NFS, that unfortunately ins’t much better at the simplicity aspect (if you use authentication), and actually, can be even worse if you use some exotic distribution without the required kernel modules.

But there’s something that all slightly more advanced users has on his file server that usually is shipped by default: SSH.

Did you know that SSH can also be used as a network file system? Let me show SSHFS.

Basically, it’s a FUSE file system that uses the SFTP of SSH as a mounted file system on a folder like any other Linux file system.

Configuring SSHFS

This tutorial aims Gentoo users, and autofs maybe useless on SystemD, since it has their own auto mounting mechanisms.

To began, install sshfs on your Linux distribution. On Gentoo, do: emerge –ask -v net-fs/sshfs

With that, now create the key pair that will be used by the system. (remember: this is a autofs tutotrial, if do you want to mount sshfs manually by the user, just use your personal key and skip all autofs configuration. And no, please, don’t use SSH with password authentication ever. This possibility will be ignored here.)

ssh-keygen -t ed25519 -C “email@email.com

Do not define a password for this key if the aim is to set autofs or even to mount the file system on boot.

Move both files (id_ed25519 e id_ed25519.pub) to .ssh folder at root user of your PC. On Gentoo, this is /root/.ssh.

Remote server

On your remote server, login with the user that you indeed to use to share files (on domestic systems, this is the user that you do everything on it), and edit the file $HOME/.ssh/authorized_keys by pasting the contents of id_ed25519.pub generated in the last step on a new line.

Usually, SFTP is already enabled by default on the server, even on OpenBSD system as the time of this writing. Nothing more to be done here.

Local system

Back to your local system, supposing that you want to use the /mnt/Array folder as monting point, let’s test if the remote folder can be mounted.

In the command below, change the user before @ with the one that has the configured public key for your user, and after @ with the IP of the server (below, a IPv6 is being used). After : there’s the target folder name at the remote server that will be mounted locally.

    fbugno@Wilhelm ~ $ sudo sshfs -o rw,allow_other,reconnect,transform_symlinks sshfs@[fdcd:79d:25ec:321::2]:/Array /mnt/Array/
    fbugno@Wilhelm ~ $ ls /mnt/Array  
    Albuns Anime Backups bin Downloads EBooks Emuladores Series Vídeos
    fbugno@Wilhelm ~ $ df /mnt/Array
    Sist. Arq.                                Blocos de 1K      Usado Disponível Uso% Montado em
    sshfs@[fdcd:79d:25ec:321::2]:/Array   7813562368 5521922592 2282355296  71% /mnt/Array

If everything went ok, the files on /Array are the remote server (in this example, your folder will have another name) will be available locally now at /mnt/Array.

Autofs

First step is to install autofs:

emerge -av autofs

Now, add it to system boot:

rc-update add autofs default

On autofs configuration, open the file /etc/autofs/auto.master and add the following:

/- /etc/autofs/auto.sshfs --timeout=30

Create the file /etc/autofs/auto.sshfs with the following content:

/mnt/Array     -fstype=fuse,rw,allow_other,reconnect,transform_symlinks,IdentityFile=/root/.ssh/id_ed25519 :sshfs\#sshfs@[fdcd:79d:25ec:321::2]\:/Array

Yes, before the “#” there’s the FUSE file system type, and following, the user name to be used to connect with your remote server.

Before rebooting the system, test it with: sudo automount -f -v

Now, in another terminal, attempt to access the folder /mnt/Array and check if the files do show there. If yes, everything is ok.

Now you can either reboot the system or restart the automount as a daemon. If the system has no network connection, it will wait 30 seconds before giving up.