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.
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.
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 [email protected]:/home/ubuntu/ /mnt/test/
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
Note: Getting a connection error? Try troubleshooting with one of our guides:
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]
Alternatively, navigate to the folder in a GUI file browser.
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.
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\[email protected]
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:
Step 4: Unmount Remote File System on Windows via Explorer
To unmount the disk, right-click the mounted device and select Disconnect:
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\[email protected]
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.[email protected]
is the remote user and host.
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
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
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.
Step 2: Configure Connection
Fill out the necessary fields and select the options for your scenario:
- 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.
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:
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.