Mount in One Command
On your Linux computer or on a second server, as a normal user:
mkdir -p ~/mnt
sshfs user@your_server_ip:/var/www/ ~/mnt
ls ~/mnt
The files in /var/www on the server now appear in ~/mnt. No root is needed on either side, and the server needs only its normal SSH service with SFTP turned on, which it is by default. If SSH login does not work yet, start with how to SSH into a server.
Install SSHFS
# Debian and Ubuntu
sudo apt install sshfs
# AlmaLinux and Rocky Linux (EPEL)
sudo dnf install epel-release
sudo dnf install fuse-sshfs
Install it on the machine where you mount, not on the server. The project's README says SSHFS has no active regular contributors; its maintainer still applies pull requests and makes releases.
Unmount
fusermount3 -u ~/mnt
On systems with the older FUSE 2 tools the command is fusermount -u ~/mnt; sudo umount ~/mnt also works. If it reports that the device is busy, a shell or editor is still using the folder: close it or change directory, then try again.
Useful Options
sshfs -p 2222 user@your_server_ip:/var/www/ ~/mnt \
-o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 \
-o IdentityFile=$HOME/.ssh/id_ed25519
-p 2222: SSH port, if it is not 22.reconnect: reconnects after a dropped connection instead of leaving a dead mount. Files that were open return errors and must be opened again.ServerAliveInterval=15: sends a keepalive every 15 seconds, so a broken link is noticed;ServerAliveCountMax=3gives up after three missed replies, about 45 seconds.IdentityFile: the private key to use.idmap=user: shows files owned by the remote user as yours.
SSHFS also reads your SSH config file, so ports and keys set there apply.
Permissions
You can do on the mount exactly what the SSH user can do on the server, nothing more. Files you create belong to that user. sudo on your side does not give root rights on the server; to edit root-owned files, change their ownership on the server or work over SSH.
Mount at Boot with fstab
Test the mount by hand first. Then, with key login that needs no passphrase prompt, add a line to /etc/fstab:
user@your_server_ip:/var/www/ /home/deploy/mnt fuse.sshfs x-systemd.automount,_netdev,reconnect,ServerAliveInterval=15,IdentityFile=/home/deploy/.ssh/id_ed25519,allow_other,default_permissions 0 0
The mount is made by root, so connect once with sudo ssh using that key to accept the host key. allow_other lets users other than root open the mount, and default_permissions makes the kernel check file permissions; a normal user who mounts with allow_other also needs the line user_allow_other in /etc/fuse.conf. With x-systemd.automount, the folder is mounted on first access, and a missing server does not hold up the boot. Run sudo systemctl daemon-reload and sudo systemctl start home-deploy-mnt.automount, then ls /home/deploy/mnt to test.
What SSHFS Is Not For
Every file operation is a round trip over the network. Listing a large tree or opening thousands of small files is slow, and a dropped connection can leave a half-written file. Use SSHFS for browsing and light editing, not as:
- A backup target: it has no versions and no consistency checks. Use rsync or BorgBackup.
- A place for databases: they need fast, reliable local storage and file locking.
- A bulk copy tool: scp or rsync move large amounts of data faster.
Troubleshooting
- Transport endpoint is not connected: the connection dropped. Unmount with
fusermount3 -u ~/mnt(add-zfor a lazy unmount if that fails), mount again, and addreconnect. - Connection reset by peer: the SSH login failed. Test with
ssh user@your_server_ipfirst. - Mount point is not empty: mount on an empty folder.
- Permission denied on a file: the SSH user lacks rights to it on the server.