SSHFS: Mount Remote File Systems on Linux & Windows

August 20, 2024

Introduction

SSHFS (SSH File System) is a command-line tool that uses an SSH connection to mount remote file systems onto a local machine. The SSHFS client uses SFTP to set up local access to remote physical or virtual disks, simplifying remote file management.

This article shows how to use SSHFS to mount remote file systems on Linux and Windows.

SSHFS: Mount Remote File Systems on Linux & Windows.

Prerequisites

  • Command-line access.
  • Administrative privileges on the local system.
  • Remote file system credentials.

Note: The recommended way to connect via SSH is to utilize SSH key pairs. Follow our tutorials on how to generate SSH key pairs on different operating systems:

Installing SSHFS

SSHFS does not come preinstalled on Windows and major Linux distributions. Refer to the sections below for instructions on installing SSHFS.

Install SSHFS on Linux

The command to install SHHFS depends on the Linux distribution and the package manager running on the system. Below are the commands for the two most popular scenarios:

  • Install SSHFS on an Ubuntu/Debian system using the apt package manager:
sudo apt install sshfs
  • Install SSHFS on a RHEL-based system using the yum package manager:
sudo yum install fuse-sshfs

Install SSHFS on Windows

Setting up SSHFS on Windows requires downloading and installing the following programs:

  • The latest stable version of WinFS.
  • The latest stable version of SSHFS-Win.
  • The SSHFS-Win Manager frontend GUI interface (optional). Download the GUI manager on the SSHFS-Win GitHub page.
SSHFS-Win download page.

Mount Remote File System on Linux

The terminal is the simplest way to mount a remote directory in Linux. The steps below provide a detailed explanation of the mounting procedure.

Step 1: Create Mount Point

To create a mount point directory in /mnt, type the command below:

sudo mkdir /mnt/[mount-point-directory]

Replace [mount-point-directory] with a new directory name.

Step 2: Mount Remote File System Using SSHFS

Mount the remote file system to the mount point created in the previous step. Use the following SSHFS syntax:

sudo sshfs -o [options] [remote-user]@[remote-host]:/[path to remote directory] /mnt/[mount-point-directory]/

If the remote server uses password authentication, enter the password when requested. If it uses SSH key authorization, provide the path to the private key using the IdentityFile option. For example:

sudo sshfs -o allow_other,default_permissions,IdentityFile=/home/kb/.ssh/id_rsa ubuntu@131.153.142.254:/home/ubuntu/ /mnt/test/
Output of the SSHFS command in Linux.

The above command mounts a remote directory at 131.153.142.254 under the name ubuntu to the /mnt/test/ mount point.

The -o flag introduces the following options:

  • allow_other. Allows access to users other than root.
  • default_permissions. Enables permission checking by the kernel.
  • IdentityFile. Allows the user to provide a path to a private key for SSH key authentication.

For a comprehensive list of available options, enter:

sshfs -h

Step 3: Check Mounted File System

Check if the file system is mapped correctly by navigating to the mount point directory with the cd command:

cd /mnt/[mount-point-directory]
Checking contents of directory using the cd command.

Alternatively, navigate to the folder in a GUI file browser.

Checking mounted file system using GUI.

Step 4: Unmount Remote File System on Linux

To stop using the mount point and interrupt the connection with the remote file system, unmount the remote directory with the umount command:

sudo umount /mnt/[mount-point-directory]

If successful, the command provides no output.

Note: Double-check if you typed the umount command correctly. There is no letter N.

Mount Remote File System on Windows

Windows offers several solutions for mounting remote file systems, including the command line, Windows Explorer, and GUI. The following sections provide steps for each solution.

Via Windows Explorer

Follow the steps below to mount a remote file system using SSHFS and Windows Explorer.

Step 1: Find Map Network Drive Option

Open Windows Explorer. Right-click This PC from the menu in the left pane and select Map network drive.

Map network drive in Windows Explorer.

Step 2: Mount Remote File System Using SSHFS

Select the drive letter for the remote folder in the Map network drive dialog. Type the following sshfs command in the Folder field:

\\sshfs[.option]\[remote user]@[remote host][!port][\path]

Note: The default port for SSH connections is 22. Malicious actors are aware of this, too. Change the default port if you deal with sensitive information.

Depending on your use case, the sshfs command offers the following options:

  • sshfs maps the remote user's home directory.
  • sshfs.r connects to the remote user's root directory.
  • sshfs.k maps the remote user's home directory and uses the SSH key stored in [local-user]/.ssh/id_rsa.
  • sshfs.kr adds the remote user's root directory and uses the locally stored SSH key.

For example:

\\sshfs.k\ubuntu@131.153.240.35
Mapping network folder using sshfs.

Click Finish to map the remote file system. Upon successfully connecting, the remote file system opens in the File Explorer.

Step 3: Check Mounted File System

The newly mounted file system is visible in the Network locations section of the This PC view:

Mounted file system in Windows Explorer.

Step 4: Unmount Remote File System on Windows via Explorer

To unmount the disk, right-click the mounted device and select Disconnect:

Disconnecting mounted device on Windows Explorer.

Via Command Prompt

Mounting a remote file system in Windows via the command line is a one-command operation. Read the steps below to learn how to mount directories using SSHFS.

Step 1: Mount Remote File System With net use

Use the net use command to mount the remote file system:

net use [drive letter]: \\sshfs[.option]\[remote user]@[remote host][!port][\path]

For example:

net use X: \\sshfs.k\ubuntu@131.153.240.35

The command does the following:

  • X: assigns the drive letter to the remote folder.
  • sshfs.k allows you to submit an SSH key stored in [local-user]/.ssh/id_rsa.
  • ubuntu@131.153.240.35 is the remote user and host.
Mounting remote file system using net use command.

The output of the command informs of a successful connection.

Step 2: View Mounted Device(s)

To view the currently mounted disks through SSHFS, run:

net use
Output of the net use command.

The command outputs the local mount point name and the remote connection point.

Step 3: Unmount Remote File System on Windows via CMD

To remove the mapped device from your system, run the following:

net use [drive-letter]: /delete

For example, if the remote file system is on the drive X, use:

net use X: /delete
Deleting mounted device using net use delete.

Via SSHFS-Win Manager

The SSHFS-Win Manager offers a convenient and easy-to-use GUI for establishing and managing remote server connections. Follow the steps below to use SSHFS-Win to map a new remote directory.

Step 1: Run SSHFS-Win Manager

Search for SSHFS-Win Manager in the Start menu and run the program. Click the Add Connection button in the menu on the right side to add a new connection.

SSHFS Win-Manager add device button.

Step 2: Configure Connection

Fill out the necessary fields and select the options for your scenario:

Adding a connection using SSHFS Win-Manager.
  • Name is a custom name for your connection.
  • IP/Host is the host address.
  • Port is 22 by default for SSH connections. Leave it as is if you did not change the port.
  • User is the username of the remote system.
  • The Authentication method is either through a private key file or a password. If using the secret key file, provide the path. Alternatively, the password option allows providing a password immediately or when establishing a connection.
  • The Remote path is the path to the remote file system.
  • Local drive letter lists locally available drive letters for a mount point.

Click Save when you are done filling out the fields. The newly created server connection shows up in the main menu.

SSHFS Win-Manager added connection.

Step 3: Mount Remote File System and View Contents

Click the socket icon next to your connection name to establish a connection. If the connection succeeds, the socket icon changes to a green connected socket, and a folder icon appears:

Established connection in SSHFS Win-Manager.

Click the folder icon to view the contents of the remote file system.

Step 4: Unmount Remote File System on Windows via SSHFS Win-Manager

To unmount the server connection, click the socket icon in the SSHFS Win-Manager menu. If the connection is no longer needed, delete the information using the Delete mode button.

Note: For SSHFS on macOS, read our guide How to Mount Remote File Systems via SSHFS on macOS
.

Conclusion

SSHFS provides a secure way to mount a remote directory to a local machine. The connection uses the SSH file transfer protocol for each transferred file, ensuring secure communication between two points.

An alternative way to transfer files via SSH is through remote sync. Check out our guide, How to Transfer Files with Rsync, and see which method suits you best.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
How to Transfer Files with Rsync over SSH
January 31, 2020

Rsync is a Linux tool that allows you to transfer data over SSH to a remote server securely. Use the options for the rsync command to adapt the tool for your specific use case.
Read more
How Does SSH Work?
December 17, 2020

SSH is a network protocol designed to provide a more secure network communication by employing encryption. This article deals with the mechanism behind SSH and its layers, and lists some of its common use cases.
Read more
Telnet vs. SSH: How Is SSH Different From Telnet?
May 20, 2021

Telnet and SSH are network protocols used to connect to remote system. This tutorial covers the ways they work, what makes them different, and when to use them.
Read more
19 Common SSH Commands in Linux With Examples
September 5, 2024

Secure Shell is an important protocol for anyone managing and controlling remote machines. This guide covers the most useful commands such as specifying a...
Read more