How to Use SSHFS to Mount Remote Directories over SSH

By 

Updated on

6 min read

Terminal using SSHFS to mount a remote directory over SSH

SSHFS (SSH Filesystem) is a filesystem client based on FUSE for mounting remote directories over an SSH connection. SSHFS uses the SFTP protocol, which is a subsystem of SSH and is enabled by default on most SSH servers.

When compared to other network file system protocols such as NFS and Samba , the advantage of SSHFS is that it does not require any additional configuration on the server side. To use SSHFS you only need SSH access to the remote server.

Because SSHFS uses SFTP , all data transmitted between the server and the client is encrypted and decrypted. This results in slightly degraded performance compared to NFS and higher CPU usage on both the client and server.

This guide explains how to install SSHFS on Linux, macOS, and Windows and how to mount a remote directory.

Quick Reference

TaskCommand
Mount remote directorysshfs user@host:/remote/dir /local/mountpoint
Mount with SSH keysshfs -o IdentityFile=~/.ssh/id_rsa user@host:/remote/dir /local/mountpoint
Mount with custom portsshfs -o port=2222 user@host:/remote/dir /local/mountpoint
Mount with reconnectsshfs -o reconnect,ServerAliveInterval=15 user@host:/remote/dir /local/mountpoint
Unmountfusermount -u /local/mountpoint
List SSHFS mountsmount | grep fuse.sshfs
Install on Ubuntu/Debiansudo apt install sshfs
Install on Fedora/RHELsudo dnf install fuse-sshfs

Installing SSHFS

SSHFS packages are available for all major operating systems.

Ubuntu, Debian, and Derivatives

SSHFS is available from the default Ubuntu and Debian repositories. Update the packages index and install the sshfs client:

Terminal
sudo apt update
sudo apt install sshfs

Fedora, RHEL, and Derivatives

On Fedora, RHEL, and derivatives, run the following command to install SSHFS:

Terminal
sudo dnf install fuse-sshfs

macOS

On macOS, SSHFS requires macFUSE. Install macFUSE first, then install an SSHFS build from the official SSHFS releases:

Terminal
brew install --cask macfuse
Warning
Homebrew no longer ships a maintained sshfs formula for macOS. After installing macFUSE, download a compatible SSHFS package from the official SSHFS releases or follow the current instructions in the macFUSE SSHFS guide .

Windows

Windows users need to install two packages:

  • WinFsp — a Windows filesystem driver required by SSHFS-Win
  • SSHFS-Win — the SSHFS client for Windows

Install WinFsp first, then install SSHFS-Win.

Mounting a Remote File System

The following instructions apply to Linux and macOS.

To mount a remote directory, the SSH user must have access to it. The sshfs command takes the following form:

txt
sshfs [user@]host:[remote_directory] mountpoint [options]

The sshfs command reads the SSH config file and applies per-host settings automatically. If the remote directory is not specified, it defaults to the remote user’s home directory.

For example, to mount the home directory of a user named linuxize on a remote host with IP address 192.168.121.121, first create a directory to use as a mount point:

Terminal
mkdir ~/linuxizeremote

Then mount the remote directory:

Terminal
sshfs linuxize@192.168.121.121:/home/linuxize ~/linuxizeremote

You will be prompted for the user’s password. To avoid entering the password each time you mount, set up passwordless SSH login using SSH keys.

Once mounted, you can interact with the remote files as if they were local — edit, delete, rename, or create new files and directories.

Verify the mount is active:

Terminal
mount | grep fuse.sshfs
output
linuxize@192.168.121.121:/home/linuxize on /home/linuxize/linuxizeremote type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

Common Mount Options

You can pass options to sshfs with the -o flag. Multiple options are separated by commas:

Terminal
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 linuxize@192.168.121.121:/home/linuxize ~/linuxizeremote

Useful options:

  • -o reconnect — reconnect automatically if the connection is interrupted
  • -o ServerAliveInterval=15 — send a keep-alive packet every 15 seconds
  • -o ServerAliveCountMax=3 — disconnect after 3 unanswered keep-alive packets
  • -o allow_other — allow other users on the local machine to access the mount (requires user_allow_other in /etc/fuse.conf)
  • -o follow_symlinks — follow symbolic links on the remote host
  • -o IdentityFile=~/.ssh/id_rsa — specify which SSH private key to use
  • -o port=2222 — connect to a non-standard SSH port
  • -o compression=yes — enable compression (useful on slow connections)

Persistent Mount with /etc/fstab

To mount a remote directory automatically at boot, add an entry to the local machine’s /etc/fstab file. Use fuse.sshfs as the filesystem type.

When creating a persistent mount, SSH key-based authentication is required since there is no interactive prompt at boot time.

/etc/fstabsh
user@host:/remote/dir  /local/mountpoint  fuse.sshfs  defaults,_netdev,nofail,x-systemd.automount,IdentityFile=/home/user/.ssh/id_rsa,reconnect,ServerAliveInterval=15  0  0

The key options for SSHFS fstab entries:

  • _netdev — tells the system this is a network mount; wait for the network before mounting
  • nofail — do not report an error if the remote host is unreachable at boot
  • x-systemd.automount — mount on first access rather than at boot (avoids boot delays)
  • IdentityFile — path to the SSH private key

After editing /etc/fstab, test the entry without rebooting:

Terminal
sudo mount -a

Mounting a Remote Directory on Windows

Windows users can use Windows Explorer to map a network drive to the remote directory.

Open Windows Explorer, right-click on “This PC”, and select “Map network drive”. Choose a drive letter and enter the remote path in the following format in the “Folder” field:

txt
\\sshfs\user@host[\PATH]

Unmounting a Remote File System

To detach a mounted SSHFS filesystem, use either fusermount or umount followed by the mount point:

Terminal
fusermount -u ~/linuxizeremote
Terminal
umount ~/linuxizeremote

If the mount is unresponsive (for example, after a network interruption), add the -z flag to force a lazy unmount:

Terminal
fusermount -uz ~/linuxizeremote

Troubleshooting

“Transport endpoint is not connected”
This error appears when the SSHFS connection dropped but the mount point was not cleaned up. Unmount with fusermount -uz /local/mountpoint and remount. To prevent this, use the -o reconnect,ServerAliveInterval=15 options when mounting.

“Connection reset by peer” or mount goes unresponsive
The SSH server dropped the connection due to inactivity. Add -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 to your mount command or fstab entry to keep the connection alive and reconnect automatically.

“Permission denied (publickey)”
SSH key-based authentication failed. Check that the correct key is being used with -o IdentityFile=~/.ssh/id_rsa and that the public key is present in ~/.ssh/authorized_keys on the remote host.

Mount disappears after reboot
If the mount was created manually with sshfs, it does not survive a reboot. Add an entry to /etc/fstab with the _netdev and x-systemd.automount options as shown in the persistent mount section.

Other users cannot access the mount
By default, only the user who created the SSHFS mount can access it. To allow other users, mount with -o allow_other and ensure /etc/fuse.conf contains the line user_allow_other.

FAQ

What is the difference between SSHFS and SCP or rsync?
SCP and rsync transfer files between systems — they copy files from one place to another. SSHFS mounts the remote directory so you can access it in place, using any application or tool as if the files were local. No copying is needed.

Does SSHFS work with password authentication?
Yes, for manual mounts. You will be prompted for a password on each mount. For persistent fstab mounts or automated scripts, SSH key-based authentication is required since there is no prompt at boot time.

Is SSHFS suitable for high-performance file transfers?
SSHFS has higher latency than NFS or direct access because all data is encrypted over SSH. It is well suited for occasional file access and editing. For large-scale or performance-critical transfers, use rsync or NFS.

How do I mount as a different user?
Specify the remote username in the mount command: sshfs remoteuser@host:/path /local/mountpoint. The remote user must have read access to the directory being mounted.

Conclusion

SSHFS is a simple way to access remote files over SSH without any server-side configuration. For a complete list of options, run man sshfs in your terminal. To further secure your SSH server, consider setting up an SFTP chroot jail for restricted users and changing the default SSH port .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page