1. Blog
  2. Manuals

SSHFS: Mount a Remote Directory over SSH

SSHFS: Mount a Remote Directory over SSH

SSHFS mounts a directory from a remote server as an ordinary local folder. Nothing has to be installed on the server: a working SSH service is enough. It is handy when you want to edit server files in your usual editor or copy data quickly.

Installation

Ubuntu and Debian:

sudo apt install sshfs

Fedora, AlmaLinux, Rocky Linux:

sudo dnf install fuse-sshfs

Arch Linux:

sudo pacman -S sshfs

macOS: install macFUSE and the SSHFS package from the macFUSE project site.

Windows: install WinFsp and SSHFS-Win, then map a network drive in File Explorer using an address like \\sshfs\user@203.0.113.10.

Mounting

Create a mount point and attach the remote directory:

mkdir -p ~/remote
sshfs user@203.0.113.10:/var/www ~/remote

If no path follows the colon, the user’s home directory is mounted. You can now work with files in ~/remote as if they were local.

Useful options

sshfs user@203.0.113.10:/var/www ~/remote \
  -p 2222 \
  -o IdentityFile=~/.ssh/id_ed25519 \
  -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3
  • -p 2222 — a non-standard SSH port;
  • IdentityFile — key-based login instead of a password;
  • reconnect together with ServerAliveInterval — reconnect automatically after the link drops; without them the folder hangs when the network is lost;
  • allow_other — let other system users access the folder. Requires user_allow_other in /etc/fuse.conf;
  • ro — mount read-only.

If the server is described in ~/.ssh/config, as shown in the SSH connection guide, the command shrinks to sshfs web:/var/www ~/remote.

Unmounting

fusermount -u ~/remote

On macOS use umount ~/remote. If the folder is busy, find the process with lsof +D ~/remote or force a lazy unmount: fusermount -uz ~/remote.

Automounting through fstab

Add a line to /etc/fstab:

user@203.0.113.10:/var/www /mnt/remote fuse.sshfs noauto,x-systemd.automount,_netdev,reconnect,ServerAliveInterval=15,IdentityFile=/home/user/.ssh/id_ed25519,allow_other 0 0

The noauto,x-systemd.automount options mount the directory on first access rather than at boot, so the system does not wait for the network on start-up. The key must have no passphrase, and the server fingerprint must already be in root’s known_hosts.

Apply the settings:

sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target

Limitations

  • Speed. Every file operation goes through the network and encryption. For directories with thousands of small files SSHFS is noticeably slower than NFS.
  • Not for databases. Do not put database files or other write-heavy data on SSHFS.
  • Project status. SSHFS is in maintenance mode: no new features are added, but the package remains in the repositories of all major distributions and works reliably.

Alternatives