Oct 23, 2023 4 min read

How to Umount non-sudo SSHFS Created Directory

Unmount non-sudo SSHFS created directory with our step-by-step tutorial. The file system that mounts a remote directory using SSH is called SSHFS.

Umount non-sudo SSHFS Created Directory
Table of Contents

Introduction

Before we start talking about how to umount non-sudo SSHFS created directory, let's briefly understand-What is SSHFS ?

SSHFS (SSH Filesystem) allows you to mount remote directories over SSH, providing a convenient way to access files and directories on remote machines. However, when you mount an SSHFS directory without using sudo, it requires different steps to unmount it.

The file system that mounts a remote directory using ssh is called SSHFS. A remote directory mounted locally using the SSH Filesystem (SSHFS) tool without invoking the sudo command is referred to as a non-sudo SSHFS directory. Mounting the directory is simple, but unmounting it can be challenging. This poses the question of how to unmount a directory mounted with non-sudo SSHFS. The fusermount command is used for this.

In this tutorial, we will explore the process of unmounting a non-sudo SSHFS created directory, allowing you to safely disconnect from the remote machine. We will also address a few FAQs on how to umount non-sudo SSHFS created directory.

Prerequisite

Linux does not come with the SSHFS preloaded, but it may be installed using these commands:

sudo apt install sshfs            #Ubuntu/Debian
sudo yum install fuse-sshfs       #CentOS/RHEL

The screenshot above shows that SSHFS has been installed on Ubuntu 22.04 LTS.

Mount a Directory from a Local to Remote Machine

Follow this detailed guide to mount a directory from a local machine to a remote machine using SSHFS. In this case, the remote directory with the name "rfolder" is mounted to the remote host "[email protected]" directory "office".

sshfs [email protected]:rfolder ~/office

The rfolder directory has been successfully mounted to the office directory, as shown in the image above.

Method 1: Using the umount Command

Unmounting a remote directory made with SSHFS but without sudo privileges is possible. The "umount" command, a command-line tool used to unmount a file system from a directory, is used to complete the process.

Syntax:

umount [options] filesystem

Users can unmount or remove a remote file system using the umount command in the syntax above.

Use the following man command to display a list of options:

man umount

Now, run the following command to unmount the earlier mounted office directory established via non-sudo SSHFS:

umount office

The output demonstrates the unmounting of the office directory.

Note: Some users can get errors like "Permission denied," and if that occurs, use the fusermount command as follows.

Method 2:  Using the fusermount Command

A FUSE filesystem can be mounted or unmounted using the fusermount command. It provides a method for unmounting file systems without requiring root access and enables non-root users to mount file systems. The fusermount command is used in the following manner to unmount the fuser systems:

Syntax:

fusermount [OPTIONS] MOUNTPOINT

In this case, the MOUNTPOINT should be changed to a directory where a user can gain access to an external file system.

Use the following man command to display a list of options:

The fusermount command can be used to unmount a non-sudo SSHFS generated directory (such as the previously mounted office directory). The "office" directory is unmounted in this case using the "-u" flag:

fusermount -u office

The image up top demonstrates that the office directory was successfully unmounted.

FAQs: Unmounting a Non-Sudo SSHFS Created Directory

Why does unmounting a non-sudo SSHFS directory require different steps?

When you mount an SSHFS directory without using sudo, it is associated with your user's mount namespace instead of the system's mount namespace. As a result, you need to execute specific commands as your user to unmount it.

How can I find the mount point of the SSHFS directory? 

To find the mount point of an SSHFS directory, you can check the output of the mount command. Look for lines containing the remote server hostname or IP address and the local directory where it is mounted.

What is the command to unmount an SSHFS directory mounted without sudo?

To unmount an SSHFS directory mounted without sudo, use the fusermount command. The command should be executed as your user, with the -u option followed by the local directory's path.

What if I get a "device is busy" error when unmounting an SSHFS directory? 

If you get a "device is busy" error while trying to unmount the SSHFS directory, it means that files or processes inside the directory are still active. Make sure to close all file explorers, terminals, or applications accessing the mounted directory before attempting to unmount it.

Can I unmount an SSHFS directory created by another user?

No, you can only unmount an SSHFS directory created by yourself. If you are unable to unmount the directory, ask the user who mounted it to perform the unmounting process.

Is it possible to unmount all SSHFS mounted directories at once? 

Yes, it is possible to unmount all SSHFS mounted directories at once. You would need to execute the fusermount command with the -u option followed by the paths of all the directories you wish to unmount.

Can I remount an SSHFS directory after unmounting it? 

Yes, you can remount an SSHFS directory after unmounting it. The unmounting process does not affect your ability to mount the directory again.

Conclusion

The umount and fusermount commands are used on Linux to unmount a non-sudo SSHFS created directory. On the other hand, because of root privileges, the umount command may provide the error "Permission denied". Therefore, it is advised to use the fusermount command to unmount the directory that was created without using sudo SSHFS.

This tutorial demonstrated how to unmount a directory that was not created using sudo SSHFS.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.