Skip to main content

SSHFS: Mount a Remote Directory on Linux Securely

Laptop and remote server folders connected by an encrypted bridge, illustrating SSHFS file access

Copying the same files between a laptop and a server gets tiring quickly. SSHFS offers a convenient alternative: mount a remote directory in your Linux home folder, then browse it with familiar tools. It is useful for inspecting project files or reading logs, provided you understand what happens when the network disappears.

This guide uses a Linux client and an SSH server with SFTP enabled. Replace every example username, host and remote path with values for a server you are authorized to access. The commands are a documented workflow, not a test of your particular server.

What is SSHFS, and when should you use it?

SSHFS combines a local FUSE filesystem with remote SFTP access over SSH. Install SSHFS on the client; the remote account needs working SFTP access and permission to the requested directory. An installed SSH server alone does not guarantee that its SFTP subsystem is enabled.

Treat the mount as a live view of remote files. Deleting a file through a writable mount can delete the server copy. Network latency, caching and connection failures also make it different from a local disk. Avoid using it for active database storage or workloads that depend on local filesystem semantics; a mount is not a backup.

1. Install SSHFS and verify SFTP access

On an Ubuntu or Debian client with the package available in its configured repositories:

sudo apt update
sudo apt install sshfs
sshfs --version

Other distributions package FUSE and SSHFS differently. Use the distribution’s supported package instructions rather than copying old CentOS package names.

sftp editor@server.example.com

On the first connection, verify the host-key fingerprint through a trusted administrator or provider channel before accepting it. At the SFTP prompt, check the permitted directory with pwd and ls, then enter bye. An SFTP-only account may have a restricted path that differs from the host’s full filesystem.

2. Mount the remote directory as your normal user

mkdir -p "$HOME/mnt/project"
sshfs editor@server.example.com:/srv/project "$HOME/mnt/project" -o ro
ls -la "$HOME/mnt/project"

Choose an empty mount directory you own. The ro option makes this first mount read-only. After confirming the path and access policy, unmount it and omit -o ro only if you need write access. Do not run the routine mount with sudo.

3. Use SSH keys and a non-default port

For an account that permits key authentication, create a dedicated key if you do not already have an appropriate one. Choose a passphrase and keep the private key on the client; send only the public key through the server’s approved enrollment process.

ssh-keygen -t ed25519 -f "$HOME/.ssh/id_ed25519_project"

A server using SSH port 2222 and that identity can be mounted as follows. Verify its host key and SFTP access on the same port first, using sftp -P 2222.

sshfs -p 2222 editor@server.example.com:/srv/project "$HOME/mnt/project" \
  -o IdentityFile="$HOME/.ssh/id_ed25519_project",ro

Key authentication avoids repeatedly entering the account password; a passphrase-protected key may still need unlocking through an SSH agent. Never remove host-key verification to make a connection error disappear.

4. Handle disconnects and unmount cleanly

sshfs editor@server.example.com:/srv/project "$HOME/mnt/project" \
  -o ro,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

Use this command instead of the earlier mount, not on top of it. Keepalive options help detect an unresponsive connection; reconnect attempts to restore it. They do not protect in-flight work: previously open files can fail and need reopening, and interrupted reads or writes can lose data.

fusermount3 -u "$HOME/mnt/project"

Save and close files first, then move any terminal out of the mounted directory. Some older distributions use fusermount -u; consult the installed manual. If unmounting reports a busy resource, identify the application still using the mount rather than immediately forcing it.

Common SSHFS problems and practical checks

SymptomWhat to check
1Permission deniedAccount authentication, remote path permissions and SFTP restrictions.
2Connection refused or timeoutCorrect host and port, network route, firewall policy and SSH service.
3Transport endpoint is not connectedClose affected applications, unmount the stale mount and reconnect after restoring connectivity.
4Unexpected ownership or accessRemote identity and UID/GID mapping. Review idmap=user and default_permissions in the installed manual.
5Slow browsingNetwork latency, file count and workload. Consider SFTP transfer or a deliberate synchronization workflow instead.

Keep the default restriction to the mounting user. allow_other broadens local access and needs a deliberate permissions review. For persistence, design an on-demand mount using your distribution’s current service guidance, credentials and failure behavior; an old blanket fstab entry can create boot or access problems.

Is SSHFS right for your next task?

Use SSHFS when interactive remote file access is the goal. Use a transfer or synchronization tool when you need an independent local copy, and a real backup system when you need recovery. Which files do you need to inspect remotely, and would a read-only mount be enough?

Make the mount reliable

For a mount that survives network blips, use options such as reconnect and ServerAliveInterval so the connection recovers and idle sessions are not dropped. Key-based authentication is safer and lets you mount without typing a password each time.

Mount at boot with fstab

To mount automatically, add an entry in the file systems table using the sshfs type, a network-dependent option and an identity file. Test it with a manual mount command before rebooting, so a typo does not delay boot.

Unmounting and troubleshooting

Unmount a user mount with fusermount using the unmount option. If you see permission denied, check key permissions and the remote path. A stale mount that hangs usually needs a lazy unmount, then a fresh mount.

Security and performance notes

Restrict the remote account to the directories it needs and avoid mounting as root. SSHFS suits convenient access and small tasks; for heavy workloads or many small files, consider NFS or rsync instead.

Frequently asked questions

Is SSHFS encrypted? Yes, it travels over SSH.

Can I use it on macOS or Windows? Third-party tools exist, though Linux support is the most mature.

Why is it slow? Latency and many small reads add overhead; try caching options or another tool.

Key takeaways

  • Use key authentication and reconnect options.
  • Test fstab entries manually first.
  • Choose NFS or rsync for heavy workloads.

Related reading: Linux Disk Space Full? 7 Safe Checks to Find the Cause · Ubuntu System Restart Required: 5 Safe Reboot Checks

A practical guide for your next challenge. A fresh perspective for everyday life. Discover both through Nandan’s latest articles.

Post Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsAppLet's connect