sshfs: Mounting Remote Filesystems over SSH

sshfs: Mounting Remote Filesystems over SSH

What You'll Learn

  • How to mount a remote directory locally with sshfs
  • When to use sshfs vs scp / rsync
  • How to fix common problems: disconnects, permissions, stale mounts

Quick Summary

  • Mount: sshfs user@host:/path ~/mnt -o reconnect,ServerAliveInterval=15
  • Unmount: fusermount3 -u ~/mnt (older systems: fusermount -u)
  • Edit files frequently → sshfs, bulk sync → rsync, one-off copy → scp

Prerequisites

  • OS: Ubuntu / Debian family (other distros differ only in the package name)
  • SSH access to the remote host (key auth recommended)
  • FUSE available locally (default on typical desktops / servers)

What is sshfs?

Conclusion: sshfs is a FUSE-based tool that mounts a remote filesystem locally over SSH, so you can read and write remote files exactly like local ones.

sshfs (SSH Filesystem) connects a remote directory to a local mount point using SSH's SFTP subsystem. Once mounted, remote files appear as local paths, so your local editor, file manager, and build tools can operate on them directly.

Where scp / rsync copy files, sshfs exposes the remote. It shines when you want to edit files in place without copying back and forth, or open remote logs in a local GUI.

Because it runs on FUSE (Filesystem in Userspace), an unprivileged user can mount without root — a key difference from NFS / CIFS.

How do you install it?

Conclusion: On Ubuntu / Debian it's a single sudo apt install sshfs, which pulls in sshfs and the required FUSE libraries.

# Ubuntu / Debian
$ sudo apt update
$ sudo apt install sshfs

# RHEL / Rocky / AlmaLinux (via EPEL)
$ sudo dnf install fuse-sshfs

# macOS (Homebrew, requires macFUSE)
$ brew install gromgit/fuse/sshfs-mac

Verify the installation:

$ sshfs --version
SSHFS version 3.7.3
FUSE library version 3.14.0

The sshfs project is currently in maintenance mode (no active new-feature development), but it is widely used and works reliably. For new builds that need more features, also consider NFS / Samba.

How do you mount a directory?

Conclusion: The base form is sshfs user@host:/remote/path /local/mountpoint. Create the mount point as an empty directory first.

1. Create a mount point

$ mkdir -p ~/mnt/server

2. Mount

$ sshfs user@server:/var/www ~/mnt/server

Omit the remote path to mount the login user's home directory.

# Mount the remote home directory
$ sshfs user@server: ~/mnt/server

3. Verify

$ ls ~/mnt/server
$ mount | grep sshfs
user@server:/var/www on /home/local/mnt/server type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

Using a non-standard port

$ sshfs -p 2222 user@server:/var/www ~/mnt/server

How do you unmount?

Conclusion: Use fusermount3 -u <mountpoint>. On older libfuse2 systems use fusermount -u.

# libfuse3 (current Ubuntu, etc.)
$ fusermount3 -u ~/mnt/server

# libfuse2 (older systems)
$ fusermount -u ~/mnt/server

Unmount fails with device is busy if you are cd'd into the mount or a process has files open there. Leave the directory and close any apps first. If it still won't release, fusermount3 -uz performs a lazy unmount.

How do you keep it stable? (practical options)

Conclusion: In practice always add reconnect and ServerAliveInterval. The mount survives brief network drops and avoids idle disconnects.

$ sshfs user@server:/var/www ~/mnt/server \
    -o reconnect \
    -o ServerAliveInterval=15 \
    -o ServerAliveCountMax=3

Frequently used options:

Option Effect
-o reconnect Reconnect automatically after a drop
-o ServerAliveInterval=15 Send keepalive every 15s to prevent idle disconnects
-o ServerAliveCountMax=3 Treat as disconnected after 3 missed replies
-o IdentityFile=~/.ssh/id_ed25519 Specify the private key
-o follow_symlinks Follow symlinks on the remote
-o idmap=user Map remote UID to the local user
-C / -o compression=yes Compress transfers (useful on slow links)
-o ro Mount read-only

With key auth and a tidy ~/.ssh/config, you can connect with just a Host alias: sshfs myserver:/var/www ~/mnt/server. See the related articles.

How do you mount automatically at boot?

Conclusion: Add a fuse.sshfs entry to /etc/fstab. Because it depends on the network, always include _netdev.

# /etc/fstab
user@server:/var/www  /home/local/mnt/server  fuse.sshfs  _netdev,reconnect,IdentityFile=/home/local/.ssh/id_ed25519,idmap=user,allow_other  0  0

If you use allow_other (let users other than the mounting user access it), it must be enabled in /etc/fuse.conf:

# /etc/fuse.conf
user_allow_other

At boot the network and keys may not be ready yet. Add _netdev, and if reliability matters prefer users,noauto for a manual / on-login mount instead of automatic mounting at boot.

Troubleshooting

Conclusion: Most issues are key/permission, a stale mount after a drop, or allow_other not enabled. Narrow it down by symptom.

Permission denied

$ sshfs user@server:/var/www ~/mnt/server
read: Connection reset by peer
  • First confirm plain SSH works: ssh user@server
  • Missing key → add -o IdentityFile=...
  • Check read/write permission on the remote directory: ls -ld /var/www

Transport endpoint is not connected (stale mount)

After a dropped connection the mount point can be left in a broken state. Unmount and re-mount.

$ fusermount3 -u ~/mnt/server
$ sshfs user@server:/var/www ~/mnt/server -o reconnect

File owner shows as nobody / a numeric UID

The local and remote UIDs don't match. Add -o idmap=user to map ownership to the mounting user.

Other users (e.g. www-data) can't access the mount

Add -o allow_other and add user_allow_other to /etc/fuse.conf.

sshfs vs scp / rsync — which to use?

Conclusion: Use sshfs for frequent in-place editing, rsync for bulk/scheduled sync, and scp for one-off copies. Their roles don't overlap.

Use case Recommended
Edit / browse the remote directly sshfs
Sync / back up large data rsync
One-off file copy scp
Reliable transfer over slow/flaky links rsync

Copy-paste templates

# Mount (practical)
mkdir -p ~/mnt/server
sshfs user@server:/var/www ~/mnt/server -o reconnect,ServerAliveInterval=15,idmap=user

# Unmount
fusermount3 -u ~/mnt/server

Next Reading