Operating System CentOS

Mount a Remote File System with SSHFS on AlmaLinux 9 and Rocky Linux 9

Install fuse-sshfs from EPEL on the RHEL 9 family, mount a remote directory over SSH as a regular user, and set up an on-demand mount in /etc/fstab.

SSHFS mounts a directory from another server over an ordinary SSH connection, so you can browse and edit remote files with local tools without setting up NFS or Samba. This guide installs it on AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9, mounts a remote directory as a regular user, and makes the mount permanent through /etc/fstab.

CentOS 6 reached end of life in November 2020. On the RHEL 9 family the procedure is close to what it was, with two differences: the package is now built against FUSE 3, and you do not need to load the fuse kernel module by hand.

Requirements

  • A client machine running a RHEL 9 family release, with a user that has sudo rights. SSHFS is only installed here.
  • A remote server you can already reach over SSH. It needs nothing extra: SSHFS uses the SFTP subsystem that OpenSSH enables by default.
  • On a container-based VPS, FUSE has to be made available by the provider. On KVM and other full virtualisation it works out of the box.

The examples use the remote user deploy on 203.0.113.10 and the remote directory /var/www.

Install SSHFS from EPEL

The RHEL 9 base repositories do not carry SSHFS. It is packaged in EPEL (Extra Packages for Enterprise Linux) under the name fuse-sshfs. Enable EPEL:

sudo dnf install epel-release

Install the package:

sudo dnf install fuse-sshfs

Check that it is available:

sshfs --version

Set up key-based SSH access

SSHFS can ask for a password, but a key is more convenient and is required for unattended mounts. Skip this section if your user can already log in to the remote server with a key.

ssh-keygen -t ed25519
ssh-copy-id deploy@203.0.113.10

Test the login. This also stores the remote host key in ~/.ssh/known_hosts:

ssh deploy@203.0.113.10 true

Mount the remote directory

You do not need root for this. Create an empty directory you own and mount the remote path on it:

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

If you leave out the path after the colon, the remote user's home directory is mounted. Confirm the mount and look at the files:

findmnt ~/remote
ls ~/remote

What you may read and change is decided by the permissions of the remote user, deploy in this case.

Useful options

Options are passed with -o, comma separated. SSH client options can be given the same way.

OptionEffect
reconnectReconnect automatically if the connection is interrupted.
ServerAliveInterval=15SSH option; detects a silently dropped connection instead of hanging on it.
-p 2222Connect to a non-standard SSH port.
IdentityFile=/path/to/keySSH option; use a specific private key.
idmap=userShow files owned by the remote user as owned by you.
allow_otherLet other local users access the mount. Combine it with default_permissions.
follow_symlinksPresent symlinks on the server as regular files.

A mount that copes with an unreliable connection looks like this:

sshfs deploy@203.0.113.10:/var/www ~/remote -o reconnect,ServerAliveInterval=15,idmap=user

Unmount

fusermount3 -u ~/remote

If that reports "Device or resource busy", a shell or program still has its working directory inside the mount. Leave the directory and try again.

Mount automatically with /etc/fstab

For a permanent mount, add a line to /etc/fstab with sshfs as the file system type. Mounts from fstab are performed by root, so root needs a key of its own that the remote user accepts, and root must have the remote host key stored.

Create the key and mount point, install the key on the remote server, and connect once to accept the host key:

sudo ssh-keygen -t ed25519 -N "" -f /root/.ssh/id_ed25519
sudo mkdir -p /mnt/remote
sudo cat /root/.ssh/id_ed25519.pub

Append the printed public key to /home/deploy/.ssh/authorized_keys on the remote server, then:

sudo ssh -i /root/.ssh/id_ed25519 deploy@203.0.113.10 true

Open /etc/fstab with sudo nano /etc/fstab and add one line:

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

_netdev marks the mount as needing the network. noauto,x-systemd.automount makes systemd mount it on first access rather than during boot, so an unreachable remote server cannot delay or break startup. Activate and test it:

sudo systemctl daemon-reload
sudo systemctl start mnt-remote.automount
ls /mnt/remote

Troubleshooting

  • "Connection reset by peer" or "read: Connection reset": the SSH login itself failed. Run the plain ssh command for the same user and host; whatever it reports is the real error.
  • The mount hangs after a network outage: mount with reconnect and ServerAliveInterval=15. Files that were open when the link dropped have to be reopened.
  • Slow with many small files: every operation is a round trip over SFTP. SSHFS is comfortable for editing and occasional copies, not for build trees or databases.

Project status

SSHFS still works and is packaged by the major distributions, but upstream development has slowed. The project's README states that it currently has no active, regular contributors, while the maintainer continues to apply pull requests and publish releases. For an occasional admin mount that is fine. If you need a network file system that many clients depend on, NFS is the better-supported choice on this distribution family.

Frequently asked questions

Do I have to install anything on the remote server?

No. SSHFS talks to the SFTP server that is part of OpenSSH. If sftp deploy@203.0.113.10 works, SSHFS will too.

Is the traffic encrypted?

Yes. Everything travels inside the SSH connection, with the same encryption and host-key verification as an interactive SSH session.

Why do files show the wrong owner?

By default SSHFS shows the numeric user and group IDs from the remote server, which may belong to different accounts locally. Mount with idmap=user to present the remote login user's files as your own. Access is still decided on the remote side.

Can I mount as root on the remote side?

You can if the remote server permits root logins over SSH, but it is safer to connect as an unprivileged user that owns the directory you need. A mistake in a root-mounted tree affects the whole remote system.

Share story:

Continue reading other guides on How VPS.