🍵️

2022-06-20

Manual SSHFS Mount/Umount

Back in November 2020 (oh my god this blog/gemlog has lived for a long time now) I wrote about how I used sshfs and autofs to automatically mount servers that I have ssh access to as local filesystems when needed.

Over the years I've run into some trouble with this, surprisingly. When I've been offline it's sometimes taken several minutes to log in, unless I disable the autofs service. I can only assume that some process tried to check through my home directory and had to wait for autofs to time out for each remote server it tried to mount, but which process or why remains a mystery. This was not a problem I had back then, mind you. It started later; probably due to some upgrade.

I was hardly ever offline, however, so the problem wasn't very big.

Now that I've gone back using a very old laptop that's already slow I decided that mounting the remotes when needed is something I can do manually.

Still... I'm a little too lazy to do that... Usually I need at least two of the four I have configured. Why not mount all at once, right?

So this is what you do (on Linux/BSD):

1. First make sure you've configured access to your remote targets in your .ssh/config file. In my case I call the hosts in question "home", "fileserver", "acc", and "team".

2. Install sshfs (this will also install FUSE, Filesystem in User Space, which it depends on):


$ sudo apt-get install -y sshfs # Or corresponding command for your package manager of choice

3. I assume you have a directory where you put your own scripts and that you've added it to your PATH environment variable. Otherwise:


$ mkdir -p ~/.local/bin
$ echo 'export PATH="${PATH}:${HOME}/.local/bin"' >> ~/.bashrc # or corresponding setting for your shell of choice

4. Create your mount points. For me it looks like this:


$ mkdir -p ~/Remotes/{acc,fileserver,home,team}

5. Make an executable file, in my case ~/.local/bin/remnt, with the following content (substituting for your own targets):


#!/bin/bash

USAGE="Usage: ${0} [u|m]
    u  Unmount predefined remote volumes.
    m  Mount predefined remote volumes."

TARGETS="fileserver home acc team"

if [[ ${1} == "m" ]]; then
        for remote in ${TARGETS}; do
                sshfs ${remote}:. ~/Remotes/${remote}
        done
elif [[ ${1} == "u" ]]; then
        for remote in ${TARGETS}; do
                fusermount3 -u ~/Remotes/${remote}
        done
else
        echo "${USAGE}"
fi

6. ...

7. Profit!

Links

"Mount Your Tilde", 2020-11-12 (gemlog only)

-- CC0 Björn Wärmedal