---
title: "How to Use SSHFS Mount with Remote Directories over SSH"
description: "Are you tired of using SCP to push or pull remote files? Using SSHFS mount will save you from misery, and this tutorial will teach you how, step-by-step!"
canonical: "https://adamtheautomator.com/sshfs-mount/"
---

# How to Use SSHFS Mount with Remote Directories over SSH

> Are you tired of using SCP to push or pull remote files? Using SSHFS mount will save you from misery, and this tutorial will teach you how, step-by-step!

Source: https://adamtheautomator.com/sshfs-mount/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Use SSHFS Mount with Remote Directories over SSH](https://adamtheautomator.com/wp-content/uploads/2022/04/How-to-Use-SSHFS-Mount-with-Remote-Directories-over-SSH.jpg)

# How to Use SSHFS Mount with Remote Directories over SSH

[![](https://secure.gravatar.com/avatar/b4cd4a109fc359fca6ccc8a192dd75bf9a440677bb2a87da8c23f48d76b3bb39?s=192&d=mm&r=g)Edem Afenyo](https://adamtheautomator.com/author/edem-afenyo/)4 May 202210 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Command Line](/tag/command-line/)[Linux](/tag/linux/)[SSH](/tag/ssh/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Preparing the Remote Directory](#preparing-the-remote-directory)
*   [Using SSHFS Mount on Linux](#using-sshfs-mount-on-linux)
*   [Installing SSHFS and Mounting a Remote Directory](#installing-sshfs-and-mounting-a-remote-directory)
*   [Enabling Automount on Boot](#enabling-automount-on-boot)
*   [Testing the SSHFS Mount](#testing-the-sshfs-mount)
*   [Unmounting the Remote Directory](#unmounting-the-remote-directory)
*   [Using SSHFS Mount on Windows](#using-sshfs-mount-on-windows)
*   [Installing WinFsp and SSHFS-Win](#installing-winfsp-and-sshfs-win)
*   [Understanding the SSHFS Path Syntax](#understanding-the-sshfs-path-syntax)
*   [Mounting and Unmounting the Remote Directory using the Windows File Explorer](#mounting-and-unmounting-the-remote-directory-using-the-windows-file-explorer)
*   [Mounting and Unmounting the Remote Directory using the Command Line](#mounting-and-unmounting-the-remote-directory-using-the-command-line)
*   [Testing the SSHFS Mount](#testing-the-sshfs-mount-1)
*   [Conclusion](#conclusion)

Working on a remote directory as if it were a local one is more convenient, don’t you agree? Instead of pushing and pulling files remotely using [SCP](https://www.techopedia.com/definition/26142/secure-copy), [SFTP](https://www.techopedia.com/definition/1879/secure-file-transfer-protocol-sftp), or [FTP](https://www.techopedia.com/definition/1872/file-transfer-protocol-ftp), what if you could manage those files directly? Lucky for you, the [SSHFS](https://github.com/libfuse/sshfs) mount is a quick solution to this dilemma.

This tutorial will teach you how to use SSHFS mount so you can access the remote directory contents on your local machine. Whether you’re a Windows or Linux user, this tutorial’s got you covered.

The specific use-case example in this tutorial demonstrates updating a website’s contents on a remote server’s SSHFS mounted directory. But, the general concept should apply to your specific situation and is not limited to web servers only.

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   A Linux web server – This tutorial will use a [Fedora](https://getfedora.org/) 35 named `wbserver` with [Apache HTTP Server](https://www.linuxcapable.com/how-to-install-apache-httpd-on-fedora-35/) installed. This server contains the remote directory that will be the target of the SSHFS mount.
*   A Linux client – This tutorial will use a Fedora 35 client named `fedora`.
*   A Windows client (Windows 7 and above) – This tutorial uses a Windows 10 client named `win10pc`.

## Preparing the Remote Directory

This tutorial will be working on the remote directory on the `wbserver` server called `/var/www/html`. By default, only the root account has access to this folder. Since you will not be using the server’s root account, you must give the designated user account permission to the directory instead.

In this example, the designated user account for mounting and accessing the SSHFS mount is `adm1`. Follow the below steps to give `adm1` the proper permissions to `/var/www/html` on `wbserver`.

1\. Log in to `wbserver` using your preferred SSH client.

2\. Next, run the below command to give the adm1 user full access (rwx) permissions to the /var/www/html folder.

```bash
sudo setfacl -m u:adm1:rwx /var/www/html
```

3\. Lastly, confirm that the permission is correct by running the below command.

```bash
sudo getfacl -a /var/www/html
```

As you can see below, adm1 now has read/write access to the folder.

![Viewing the folder permissions](https://adamtheautomator.com/wp-content/uploads/2022/04/image-576.png)

Viewing the folder permissions

## Using SSHFS Mount on Linux

SSHFS is primarily a Linux tool, and you only need to issue a few commands to mount a remote directory to your computer. Installing the packages to enable SSHFS mount is as convenient as installing other packages on Linux through your distro’s package manager.

### Installing SSHFS and Mounting a Remote Directory

Follow the below steps to install the SSHFS mount package and mount a remote directory to a local path.

1\. Log in to your Linux client via SSH or Desktop, depending on your environment.

Related:[How to Set up the SSH Google Chrome Extension](https://adamtheautomator.com/ssh-chrome-extension/)

2\. Run the following command to install the [fuse-sshfs](https://fedora.pkgs.org/34/fedora-x86_64/fuse-sshfs-3.7.1-2.fc34.x86_64.rpm.html) package using your package manager.

> _Note: On Debian-based Linux distros, the package name is sshfs._

```basic
sudo dnf install -y fuse-sshfs
```

The package manager also installs the dependencies not yet present on your computer. And because each package size is below 100KB, the download and installation took only a few seconds to finish.

![Installing the SSHFS mount package on Fedora](https://adamtheautomator.com/wp-content/uploads/2022/04/image-577.png)

Installing the SSHFS mount package on Fedora

3\. Next, create a new folder under your home directory called mnt. This new folder is the mount point for the remote directory.

```bash
mkdir ~/mnt
```

4\. After creating the mount point, execute the below sshfs command.

This command will mount the web server’s (wbserver) remote directory (/var/www/html) to the local mount point (~/mnt) you created while using adm1’s credentials for access.

```bash
sshfs adm1@wbserver:/var/www/html ~/mnt
```

> _If the SSH server is not listening to the default port 22, you must specify the -o port <number> switch with the sshfs command. For example, if the remote server listens to port 2222, the command would be sshfs -o port 2222._

5\. If you’re connecting to the server for the first time, confirm `the` connection by pressing `Y` at the prompt—type in the account’s password and press `Enter`.

![Mounting a remote directory with SSHFS mount](https://adamtheautomator.com/wp-content/uploads/2022/04/image-578.png)

Mounting a remote directory with SSHFS mount

6\. Lastly, confirm that you’ve successfully mounted the remote directory by running the below command.

```bash
findmnt
```

You should see that the remote directory is now mounted to the local directory you specified.

![Listing the mounted file systems](https://adamtheautomator.com/wp-content/uploads/2022/04/image-579.png)

Listing the mounted file systems

### Enabling Automount on Boot

While you’ve successfully mounted the remote directory, remember that this mount status is not persistent. Restarting the computer will not automount the remote directory.

But, you can make the SSHFS mount survive computer restarts by editing the `/etc/fstab` file and enabling key-based authentication for the `adm1` account. Enabling the SSH key-based authentication ensures that the SSHFS mount will be fully automated (no password prompts).

1\. On the Linux client, generate a new SSH key pair by running the below command.

```bash
ssh-keygen
```

On the Enter file in which to save the key prompt, type in the key filename and press Enter. In this example, the key filename to save is /home/user1/.ssh/adm1@wbserver.

Leave the passphrase empty, and press Enter twice. The below screenshot shows the key pair creation result.

![Generating the key pair for the SSHFS mount](https://adamtheautomator.com/wp-content/uploads/2022/04/image-580.png)

Generating the key pair for the SSHFS mount

2\. Now, copy the key to the webserver. The command below installs the key you previously generated (/home/user1/.ssh/adm1@wbserver) to the adm1 account on wbserver.

```bash
ssh-copy-id -i /home/user1/.ssh/adm1@wbserver adm1@wbserver
```

Type in the password for adm1@wbserver at the prompt and press Enter. As you can see below, the command successfully installed the key to the server.

![Installing the SSH key to the server](https://adamtheautomator.com/wp-content/uploads/2022/04/image-581.png)

Installing the SSH key to the server

3\. SSH into wbserver using the key pair to ensure that the key-based login works.

```bash
ssh -i /home/user1/.ssh/adm1@wbserver adm1@wbserver
```

As a result, the login should succeed without asking for a password. Type exit and press Enter to log out of the wbserver.

![wbserver](https://adamtheautomator.com/wp-content/uploads/2022/04/image-582.png)

wbserver

4\. Now that you’ve configured the SSH key-based authentication for the SSHFS user account, you’re ready to configure the persistent SSHFS mount.

Open the /etc/fstab file in a text editor.

```bash
sudo nano /etc/fstab
```

5\. Append the below code to the end of the /etc/fstab file. Make sure to change the identityfile= value with the SSH key file path.

```bash
adm1@wbserver:/var/www/html /home/user1/mnt fuse.sshfs identityfile=/home/user1/.ssh/adm1@wbserver,allow_other,_netdev 0 0
```

![SSH key file path](https://adamtheautomator.com/wp-content/uploads/2022/04/image-583.png)

SSH key file path

6\. After editing, save the file, close the text editor, and reboot the computer. As you can see below, the SSHFS mount is available again after the reboot.

![Checking the SSHFS mount after reboot](https://adamtheautomator.com/wp-content/uploads/2022/04/image-584.png)

Checking the SSHFS mount after reboot

Related:[How to Add an SSH key to VS Code and Connect to a host](https://adamtheautomator.com/add-ssh-key-to-vs-code/)

### Testing the SSHFS Mount

So you’ve mounted the remote directory to your local computer. The question now is, “does it work?”. The quickest test to confirm is creating a new file and saving it to the SSHFS mount point. The file you created should then appear on the server.

By default, the _/var/www/html_ folder on the webserver is empty. When you access the website hosted on _https://wbserver_, you’ll only see the default test page, like the screenshot below.

![Viewing the default test page](https://adamtheautomator.com/wp-content/uploads/2022/04/image-585.png)

Viewing the default test page

In this example, you’ll create a new home page and confirm that the webserver displays that new page.

1\. Switch the working directory to ~/mnt, the SSHFS mount point.

```bash
cd ~/mnt
```

2\. Execute the touch command to create an index.html file and open it in the text editor.

```bash
touch index.html && nano index.html
```

3\. Now, populate the index.html file with the below HTML code, save the file, and exit the editor.

```markup
<h1>Welcome</h1>
<h2>I was put here over SSH by SSHFS</h2>
```

The screenshot below shows the expected content of the index.html file.

![Creating the new home page](https://adamtheautomator.com/wp-content/uploads/2022/04/image-586.png)

Creating the new home page

4\. Lastly, open the website URL in your web browser again. The web server should pick up and display the new home page, as you can see below.

![Updating the home page of a remote server via SSHFS mount](https://adamtheautomator.com/wp-content/uploads/2022/04/image-587.png)

Updating the home page of a remote server via SSHFS mount

Congratulations! You’ve now successfully implemented the SSHFS mount on your Linux computer. You do not need to upload or download remote files to make changes manually.

### Unmounting the Remote Directory

Suppose that you no longer need access to the remote directory via SSHFS mount and want to unmount it, run either the one of the below commands.

Run the command below if you mounted the remote directory interactively using the `sshfs` tool.

```bash
fusermount -u /home/user1/mnt
```

If you automounted the remote directory in _fstab_, run the command below instead. Additionally, you must remove the SSHFS automount entry in _fstab_. If not, the remote directory will automount again following a reboot.

```bash
sudo umount /home/user1/mnt
```

## Using SSHFS Mount on Windows

Windows computers can map network locations as local drives, such as FTP sites, network shares, and SharePoint libraries. You’ll be glad to know that you can also add SSHFS mount drives in Windows by installing a program called [SSHFS-Win](https://github.com/winfsp/sshfs-win) — a port of SSHFS on Linux.

Related:[How to Map a SharePoint Drive](https://adamtheautomator.com/map-sharepoint-drive/)

### Installing WinFsp and SSHFS-Win

SSHFS-Win requires [WinFsp](https://github.com/winfsp/winfsp) to work as it provides the underlying [FUSE](https://www.kernel.org/doc/html/latest/filesystems/fuse.html) functionality. Follow the below instructions to install both WinSfp and SSHFS-Win.

1\. Open the browser on your Windows client and download the latest release of [WinSfp](https://github.com/winfsp/winfsp/releases/latest) (v1.10) and [SSHFS-Win](https://github.com/winfsp/sshfs-win/releases/latest) (v3.5.20357).

2\. Locate the installers you downloaded and run the WinSfp installer first.

![Starting the WinFsp installer](https://adamtheautomator.com/wp-content/uploads/2022/04/image-588.png)

Starting the WinFsp installer

3\. Click Next on the Welcome to the WinFsp 2022 Setup Wizard page.

![Click Next on the Welcome page](https://adamtheautomator.com/wp-content/uploads/2022/04/image-589.png)

Click Next on the Welcome page

4\. Select all features and click Next.

![Selecting the WinFsp features to install](https://adamtheautomator.com/wp-content/uploads/2022/04/image-590.png)

Selecting the WinFsp features to install

5\. Click Install on the Ready to install WinFsp 2022 page.

![Install WinFsp](https://adamtheautomator.com/wp-content/uploads/2022/04/image-591.png)

Install WinFsp

6\. After the WinFsp installation, click Finish.

![Finishing the WinFsp installation](https://adamtheautomator.com/wp-content/uploads/2022/04/image-592.png)

Finishing the WinFsp installation

7\. Next, start the SSHFS-Win installer.

![Starting the WinSSHFS-Win installation](https://adamtheautomator.com/wp-content/uploads/2022/04/image-593.png)

Starting the WinSSHFS-Win installation

8\. Click Next on the first screen, as shown below, to start the installation process.

![Starting the SSHFS-Win Setup program](https://adamtheautomator.com/wp-content/uploads/2022/04/image-594.png)

Starting the SSHFS-Win Setup program

9\. Click Next on the Custom Setup page.

![Confirming installation settings](https://adamtheautomator.com/wp-content/uploads/2022/04/image-595.png)

Confirming installation settings

10\. On the Ready to install SSHFS-Win page, click Install.

![Installing SSHFS-Win](https://adamtheautomator.com/wp-content/uploads/2022/04/image-596.png)

Installing SSHFS-Win

11\. Finally, click Finish to complete to exit the Setup Wizard.

![Finishing the SSHFS-Win installation](https://adamtheautomator.com/wp-content/uploads/2022/04/image-597.png)

Finishing the SSHFS-Win installation

### Understanding the SSHFS Path **Syntax**

Before mapping a remote directory via SSHFS mount, review the list below to understand how SSHFS-Win interprets the remote paths.

```bash
\\\\PREFIX\\REMUSER@HOST[!PORT][\\PATH]
```

*   `REMUSER` is the remote user whose credentials you’ll use to authenticate with the remote server.
*   `HOST` is the hostname or IP address of the remote server.
*   `PORT` is the remote server’s SSH listening port. This value is optional, and the default is port 22.
*   `PATH` is the remote path relative to the `PREFIX`. The different prefixes are:
    *   `sshfs` – maps to the path relative to the user’s home directory (i.e., `HOST:~REMUSER/PATH`).
    *   `sshfs.r` – maps to a path relative to the host’s root directory (i.e., `HOST:/PATH`)
    *   `sshfs.k` – maps to the path relative to the user’s home directory (i.e., `HOST:~REMUSER/PATH`) and uses SSH key-based authentication. This prefix uses the key in `%USERPROFILE%/.ssh/id_rsa` for authentication.
    *   `sshfs.kr` – maps to a path relative to the host’s root directory (i.e., `HOST:/PATH`) and uses the key in `%USERPROFILE%/.ssh/id_rsa` for authentication.

### Mounting and Unmounting the Remote Directory using the Windows File Explorer

One way to map a network drive in Windows is through the Windows File Explorer. With this method, you do not have to run any commands, and you’ll do every step in a wizard-style GUI.

1\. Open a [File Explorer](https://support.microsoft.com/en-us/windows/find-and-open-file-explorer-ef370130-1cca-9dc5-e0df-2f7416fe1cb1) window, click **This PC** —> **Computer —> Map network drive**.

![Clicking Map network drive](https://adamtheautomator.com/wp-content/uploads/2022/04/image-598.png)

Clicking Map network drive

2\. Choose a Drive letter and type the below path into the Folder box to mount the \\var\\www\\html folder.

```powershell
\\sshfs.r\adm1@wbserver\var\www\html
```

Leave the Reconnect at sign-in option checked, and click Finish.

![Choosing a drive letter and specifying the remote folder path](https://adamtheautomator.com/wp-content/uploads/2022/04/image-599.png)

Choosing a drive letter and specifying the remote folder path

3\. Enter the account password, check the Remember me box, and click OK.

![Specifying the remote account credentials](https://adamtheautomator.com/wp-content/uploads/2022/04/image-600.png)

Specifying the remote account credentials

You have now mapped an SSHFS mount with a drive letter. And because you enabled the Reconnect at sign-in and Remember me options, Windows will reconnect the SSHFS mount after restarting the computer.

![Viewing the mapped SSHFS mount in Windows File Explorer](https://adamtheautomator.com/wp-content/uploads/2022/04/image-601.png)

Viewing the mapped SSHFS mount in Windows File Explorer

4\. At this point, you can now manage the files on the remote directory. But, if you no longer need the mapped drive and want to remove it, right-click the SSHFS mount and click Disconnect.

![Removing the mapped drive](https://adamtheautomator.com/wp-content/uploads/2022/04/image-602.png)

Removing the mapped drive

### Mounting and Unmounting the Remote Directory using the Command Line

The net use command is another way to map a remote directory in Windows. Mapping SSHFS mount drives via the command line is helpful for scripting and automation.

To mount the remote directory, open the Command Prompt or PowerShell and run the below command to map the `\\var\\www\\html` remote directory to the local computer’s drive `Z`. Make sure to change the `PASSWORD` value with the remote user’s password.

```powershell
net use Z: \\\\sshfs.r\\adm1@wbserver\\var\\www\\html PASSWORD /user:adm1
```

![Creating the SSHFS mount using the command line](https://adamtheautomator.com/wp-content/uploads/2022/04/image-603.png)

Creating the SSHFS mount using the command line

To remove the SSHFS mount drive using the command line, `delete` the mapping to drive `Z:` by running the below command.

```powershell
net use Z: /delete
```

![Removing the SSHFS mount drive](https://adamtheautomator.com/wp-content/uploads/2022/04/image-604.png)

Removing the SSHFS mount drive

Related:[How to Connect to Network Drives on the Command Line Using Net Use](https://adamtheautomator.com/net-use/)

### Testing the SSHFS Mount

Now that you have access to a locally mapped network drive, you can manage the files on the remote directory as you would any other local files. In this example, you will update the website’s home page directly from the mapped SSHFS drive.

1\. Open the File Explorer and navigate to the mapped drive.

2\. Open the file called _index.html_ in a text editor like notepad. If the file does not exist, create it first.

![Opening the file in notepad](https://adamtheautomator.com/wp-content/uploads/2022/04/image-605.png)

Opening the file in notepad

3\. Copy the HTML code below, paste it into your _index.html_ and save the file.

```markup
<h1>Welcome</h1>
<h2>I was put here over SSH by SSHFS</h2>
<h3>Brought to You from Windows 10</h3>
```

![Updating the HTML code](https://adamtheautomator.com/wp-content/uploads/2022/04/image-606.png)

Updating the HTML code

4\. Lastly, open your web browser and navigate to the website URL _HTTP://wbserver_. You should now see the updated home page you edited, confirming that your SSHFS mount works as intended.

![Viewing the updated home page](https://adamtheautomator.com/wp-content/uploads/2022/04/image-607.png)

Viewing the updated home page

## Conclusion

You’ve finally reached the end of this tutorial. You’ve learned to use the SSHFS mount to map directories to your local Windows or Linux computer from a remote SSH server. SSHFS is an excellent tool for convenience and remote file access security.

Speaking of security, perhaps you should check out [How To Secure SSH with Fail2Ban](https://adamtheautomator.com/fail2ban-ssh/) as a next step? Good luck!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fsshfs-mount%2F&text=How%20to%20Use%20SSHFS%20Mount%20with%20Remote%20Directories%20over%20SSH)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fsshfs-mount%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fsshfs-mount%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Useful-Linux-Dig-Examples-for-the-Network-Admin.jpg)

### [Linux Dig for Network Admins: Practical Guide with Examples](/linux-dig/)

Become a network troubleshooting expert! This comprehensive Linux Dig guide empowers you with essential DNS query commands for immediate results.

![](https://adamtheautomator.com/wp-content/uploads/2021/12/install-phpmyadmin.jpg)

### [Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux](/install-phpmyadmin/)

Discover how to securely install phpMyAdmin on Linux with our concise guide. Learn essential steps for a safe and efficient setup, tailored for Linux users.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
