sshfs – Securely Mount Filesystems over the Internet – Survive Suspend and Network Down

Sshfs allows you to browse your own folders over the Internet.
It’s a real mount, a directory on your computer, so any program can access the files. And it uses SSH, making it very secure.

$ sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 tero@example.com:/ mnt/tero/

The basic syntax is just like mount: mount this device over this mount point (empty folder).

$ mkdir -p mnt/tero/
$ sshfs tero@example.com: mnt/tero/

To umount (disconnect the filesystem), you don’t need root

$ fusermount -u mnt/tero/

There is just one little problem. With this setup, you would have to umount the drive before disconnecting the network – and before every suspend. Forgetting to do so would create a process in non-interruptible sleep, which would ignore kill -9 as root. That would be bad.
But here is a solution. We tell sshfs to automatically disable the mount if the server becomes unresponsive.

$ sshfs -o reconnect,ServerAliveInterval=5,ServerAliveCountMax=3 tero@example.com:/ mnt/tero/

These settings test SSH connection every five seconds (ServerAliveInterval=5) and shut it down after three failed tests (ServerAliveCountMax=3). If you lose the network (e.g. suspend), sshfs is crazy only for 15 seconds. After that, you can ‘fusermount -u’ the system and connect again without problems.
Enjoy your files from far, far away – securely.
Adminstrivia: I have not tested ServerAliveInterval settings thoroughly. This setup worked on quick test on Xubuntu 18.04 LTS amd64. Edited for style.

Posted in Uncategorized | Tagged , , , , , | Comments Off on sshfs – Securely Mount Filesystems over the Internet – Survive Suspend and Network Down

Comments are closed.