25

My coworker has a desktop computer with /home shared on our file server. I have developed a Perl script for sshfs-mounting a certain directory on another SSH host which works fine on my laptop.

On his computer the script fails to dismount the sshfs at the end and leaves the mountpoint unclean. I didn't find any way to recover the mountpoint other than rebooting. After some testing I found that the difference between our setups is that his /home is on NFS. In his /tmp it works flawlessly.

After mount, during script operation everything is fine. But when killing the sshfs process it is listed as <defunc> by ps until the parent process (the Perl script) exits. When running a raw sshfs command on the shell the problem still occurs.

A ls -dl output for the mountpoint looks like this (as remembered - I have no real copy of the shell output at hand):

? 1 ? ? 4096 Feb  9 15:37 file_archive/

(only question marks for most information, at least all permission details)

The sshfs mount is still listed by mount but an unmount operation fails with error permission denied even when doing as root.

I searched Google but only found lots of comparisons between sshfs and NFS for running network filesystems. How can I do a sshfs mount/unmount in NFS directory safely?

Gaff
  • 18,569
  • 15
  • 57
  • 68
Daniel Böhmer
  • 805
  • 1
  • 8
  • 18

5 Answers5

46

You should be able to unmount the sshfs share by executing:

 fusermount -u /path/to/sshfs/share
CJ Travis
  • 1,047
  • 7
  • 7
  • I tried this but got *permission denied*. Of course an ordinary `umount` must fail when run as non-root user. – Daniel Böhmer May 30 '11 at 15:16
  • Most likely the reason you can't unmount (with any method) is because his home dir is mount from NFS where it's exported with the `root_squash` option. Thus, root has no authority in his home dir. You might turn off `root_squash` but it's probably safer to just mount somewhere else. – JFlo Jan 07 '19 at 16:28
  • 2
    I forget everytime, that `umount` or `fusermount -u` doesnt work, when the directory is used somewhere. So `cd` out of the directory before using `fusermount -u` or use `lsof /my/local/mountpoint` – MacMartin Jan 14 '19 at 08:49
  • Returns an error message: "fuse: bad mount point `/path/to/sshfs/share': Input/output error" – Luís de Sousa Oct 08 '20 at 09:00
18

Just kill the process using pkill to and then un mount the mounted folder path.

 pkill -kill -f "sshfs" && umount /path/to/sshfs/share
SAGAR
  • 197
  • 1
  • 2
3

This post is rather old. Currently on RHEL8, this is all that is required. There is no need to kill sshfs processes:

sudo umount <mountpoint>

0

This answer refers to Ubuntu 20.04, but in general you need two steps to properly unmount a sshfs volume: i) kill the sshfs process and ii) use sudo to unmount. Without using sudo, the system reports messages like "Device or resource busy" or "Transport endpoint is not connected", even if permissions are correct.

The instructions look like:

killall sshfs
sudo umount -l /path/to/sshfs/share
Luís de Sousa
  • 348
  • 2
  • 16
-2
sudo diskutil umount force ~/mount/

Seems like this command works in OS X.

Daniel Böhmer
  • 805
  • 1
  • 8
  • 18
  • 6
    Can you expand your answer to explain what this code does and how it addresses the problem? Unexplained code is [discouraged](http://meta.stackexchange.com/questions/148272), because it doesn't teach the solution. Thanks. [from review queue](http://superuser.com/review/low-quality-posts/498566) – fixer1234 Feb 13 '16 at 18:43
  • 1
    This is for OS X. The question asked for Linux. – Dessa Simpson Dec 03 '17 at 22:51