SSHFS mount that survives disconnect

Scenario / Questions

I’m using SSHFS mounts from my laptop to a central server.

Obviously, the SSHFS mount is broken after a longer disconnect (eg. during suspend), cause the underlying SSH connection timed out.

Is there a way to get SSHFS mounts surviving long lasting disconnections (> 5 min) or even a re-dialin with a different IP?

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1:

Use -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

The combination ServerAliveInterval=15,ServerAliveCountMax=3 causes the I/O errors to pop out after one minute of network outage. This is important but largely undocumented. If ServerAliveInterval option is left at default (so without the alive check), processes which experience I/O hang seem to sleep indefinitely, even after the sshfs gets reconnect‘ed. I regard this a useless behavior.

In other words what happens on -o reconnect without assigning ServerAliveInterval is that any I/O will either succeed, or hang the application indefinitely if the ssh reconnects underneath. A typical application becomes entirely hung as a result. If you’d wish to allow I/O to return an error and resume the application, you need ServerAliveInterval=1 or greater.

The ServerAliveCountMax=3 is the default anyway, but I like to specify it for readability.

Suggestion: 2:

Thanks for the tips of autossh and autofs.

However, for my direct purpose I found a much simpler solution which wasn’t documented so well:

sshfs -o reconnect server:/path/to/mount

Suggestion: 3:

Autossh automatically reconnects ssh sessions when it notices ssh has died or stopped passing traffic. Since it is just automated ssh, it will work from different IP’s and from suspend (even if the laptop wakes up on a different lan).

Suggestion: 4:

One thing you could do is mount your filesystems via autofs. Autofs is a tool that will mount a filesystem when you to use something in the directory that the filesystem will be mounted to. When it detects activity the filesystem is mounted. When nothing is happening on the filesystem is it unmounted.

Here is a howto I found on google to accomplish this, there where several others.

Suggestion: 5:

I suspect there isn’t, because even if you can configure your SSH client not to drop the connection, the server might be configured to do so after a specified period of inactivity, and you wouldn’t be able to override that. Even if you could, if you never resume the connection, the server would be left hanging, and over time that could lead to a significant waste of server resources.

A better technique, I think, is to unmount the filesystem before suspending your computer and remount it when the computer wakes up again. The mechanism for doing so may depend on exactly how you suspend your computer – I use the tuxonice kernel and to do something like this I have a directive like

Unmount /mnt/sshfs

in /etc/hibernate/common.conf.

Suggestion: 6:

The answer of kubanczyk is great. I had a problem with freezing entire the interface because of too greedy sshfs, now for easy connection started by a script that reconnects when laptop is opened and that does not freeze when the connection gets slower, you can use a bash script like that (maybe not very secure, but convenient for many web projects for example):

echo PWD | sshfs USER@SERVER:/ MOUNT_PATH -o password_stdin,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 -p PORT -C -oStrictHostKeyChecking=no
if xhost >& /dev/null ; then
    pcmanfm MOUNT_PATH

Disclaimer: This has been sourced from a third party syndicated feed through internet. We are not responsibility or liability for its dependability, trustworthiness, reliability and data of the text. We reserves the sole right to alter, delete or remove (without notice) the content in its absolute discretion for any reason whatsoever.

Source: SSHFS mount that survives disconnect

Create your website with
Get started
%d bloggers like this: