Skip to content
SumGuy's Ramblings
Go back

SSHFS: Ditch SCP & Access Remote Files

Ever felt the frustration of needing a file from your home server, or wanting to edit a config file on your remote media server, and having to constantly scp files back and forth? It feels… clunky, right? Like you’re stuck in the digital equivalent of carrying physical files up and down stairs.

What if you could wave a magic wand and make that remote folder just appear on your local machine? What if you could open files directly in your favorite apps, save changes instantly, and treat them as if they were sitting right there on your desktop?

Well, friend, no magic wand is required. What you need is SSHFS!

In this article, we’re going on a journey from being a total SSHFS newbie to confidently using it like a pro. We’ll demystify what it is, why it’s awesome, how to get it running on your Ubuntu (and briefly, Fedora!) machine, explore some cool uses, tackle common problems, and unlock powerful tips to make your remote file access buttery smooth.

Ready to ditch the scp dance and embrace the mounted lifestyle? Let’s dive in!

So, What Exactly Is SSHFS?

Let’s break down the name: SSH FileSystem.

Put them together, and you get a way to use the secure SSH connection you already rely on to mount a remote filesystem directory onto your local machine.

Think of it like this: SSHFS creates a secure tunnel to your remote server and tricks your local operating system into thinking that remote folder is just another drive or folder attached directly to your computer.

This isn’t like SCP or SFTP, which are primarily for transferring files. With SSHFS, the files stay on the remote server, but you can interact with them locally: open, edit, save, delete, run, or even stream (though be mindful of performance!) as if they were local.

And because it uses SSH, it automatically inherits all that lovely security you’re used to – encryption, authentication (passwords or, even better, SSH keys!). No need to set up complicated, less secure protocols just for file access.

Why Would I Want to Use SSHFS? (The Superpowers!)

Okay, making a remote folder look local sounds neat, but what are the real-world benefits?

Use Cases: Where SSHFS Shines

Let’s look at some scenarios where SSHFS is a real game-changer, especially for our home lab/server enthusiasts:

These are just a few examples. Any time you find yourself frequently needing to access and interact with files on a remote Linux machine, SSHFS is probably a better solution than constant scp or SFTP sessions.

Getting Started: Installing SSHFS

Okay, enough talk! Let’s get this thing on your machine. SSHFS relies on a kernel module called FUSE (Filesystem in Userspace), which allows non-root users to mount filesystems. Luckily, modern Linux distributions have FUSE built-in, and the SSHFS tool is readily available.

We’ll focus on Ubuntu, with notes for Fedora users.

For Ubuntu Users:

Open your terminal. This is usually a single command:

sudo apt update
sudo apt install sshfs
sudo apt update
sudo apt install sshfs

That’s it! apt will handle downloading and installing SSHFS and any necessary dependencies.

For Fedora Users:

Open your terminal and use the dnf package manager:

sudo dnf install sshfs
sudo dnf install sshfs

Just like Ubuntu, dnf will sort everything out for you.

Verification:

To check if it’s installed correctly, just type:

sshfs --version
sshfs --version

You should see output showing the version number. If you get a “command not found” error, double-check the installation steps.

Basic Usage: Mounting and Unmounting Your First Remote Folder

Alright, the tool is installed. Let’s connect to a remote server!

First, make sure you can SSH into the remote server normally. You’ll need the server’s IP address or hostname, your username on that server, and potentially your password or SSH key.

Next, you need a local directory where the remote filesystem will be mounted. This directory should ideally be empty.

Let’s create one:

mkdir ~/remote_server_files
mkdir ~/remote_server_files

Now, the magic command! The basic syntax looks like this:

sshfs username@remote_host:/remote/path /local/mountpoint
sshfs username@remote_host:/remote/path /local/mountpoint

Let’s say your remote server is at 192.168.1.100, your username there is myuser, and you want to mount the /home/myuser/documents folder on the remote server to your local ~/remote_server_files directory.

The command would be:

sshfs myuser@192.168.1.100:/home/myuser/documents ~/remote_server_files
sshfs myuser@192.168.1.100:/home/myuser/documents ~/remote_server_files

When you hit Enter, SSHFS will prompt you for your remote user’s password (unless you’re using SSH keys, which you really should be – more on that later!).

If successful, you won’t see much output, but if you open your file manager and navigate to ~/remote_server_files, you should now see the contents of /home/myuser/documents from the remote server! You can interact with these files as if they were local.

Checking the Mount:

To confirm it’s mounted, you can use the df -h command (which shows disk space usage for mounted filesystems) or simply mount | grep sshfs:

df -h # Look for your mount path
mount | grep sshfs # Should show the sshfs mount details
df -h # Look for your mount path
mount | grep sshfs # Should show the sshfs mount details

Unmounting the Remote Folder:

When you’re done, it’s crucial to unmount the filesystem properly. Don’t just close the terminal or shut down your computer! Use the fusermount command with the -u flag (for unmount) followed by your local mount point:

fusermount -u ~/remote_server_files
fusermount -u ~/remote_server_files

Again, success usually means no output. Your ~/remote_server_files directory should now be empty (or show whatever was originally in it before mounting).

Important Note about umount: You might be familiar with the standard umount command. While it can sometimes work with FUSE mounts, fusermount -u is the recommended and often more reliable way to unmount filesystems mounted by a non-root user via FUSE/SSHFS.

Becoming a Pro: Advanced Options and Tips

Now that you’ve got the basics down, let’s unlock some pro moves to make your SSHFS experience even better.

1. Use SSH Keys (Seriously!)

Typing your password every time you mount is tedious and less secure than using SSH keys. If you’re not using them already, set them up! There are tons of guides online for generating SSH keys and copying them to your server (ssh-copy-id). Once set up, the sshfs command won’t prompt for a password. This is essential for automation!

2. Simplify with SSH Config File

Instead of typing myuser@192.168.1.100 every time, use the SSH configuration file (~/.ssh/config).

Edit or create the file ~/.ssh/config:

nano ~/.ssh/config
nano ~/.ssh/config

Add an entry for your server:

Host myserver
    Hostname 192.168.1.100
    User myuser
    Port 22 # Or your custom SSH port
    IdentityFile ~/.ssh/id_rsa # If you're using a specific key
Host myserver
    Hostname 192.168.1.100
    User myuser
    Port 22 # Or your custom SSH port
    IdentityFile ~/.ssh/id_rsa # If you're using a specific key

Save the file. Now you can SSH to your server just by typing ssh myserver. Even cooler? You can use the Host alias with SSHFS!

sshfs myserver:/home/myuser/documents ~/remote_server_files
sshfs myserver:/home/myuser/documents ~/remote_server_files

Much cleaner, right?

3: Performance Tuning Options

SSHFS can sometimes feel a bit slow, especially over high-latency connections or when dealing with lots of small files. Here are a few options to potentially speed things up (add these using the -o flag):

You can combine options, separated by commas:

sshfs -o cache=yes,Compression=no myserver:/remote/path /local/mountpoint
sshfs -o cache=yes,Compression=no myserver:/remote/path /local/mountpoint

Experiment with these to find what works best for your connection and workload.

4. Handling Disconnections

Internet connections can be flaky. By default, if the SSH connection breaks, your SSHFS mount will freeze up. These options can help:

sshfs -o reconnect,auto_reconnect myserver:/remote/path /local/mountpoint
sshfs -o reconnect,auto_reconnect myserver:/remote/path /local/mountpoint

5. Mounting at Boot with /etc/fstab (Advanced – Handle with Care!)

This is where you go from user-level mounting to system-level integration. You can configure SSHFS to mount automatically when your computer starts by adding an entry to the /etc/fstab file.

WARNING: This is powerful and requires SSH keys for the user SSHFS will run as. NEVER put passwords in /etc/fstab or related script files! Also, issues with the mount (like the server being unreachable) can potentially slow down or even block your boot process. Proceed with caution and ensure you have a way to edit fstab from a recovery environment if something goes wrong.

You’ll need to figure out which user should own the mount. Often, this is your regular user account.

sudo nano /etc/fstab
sudo nano /etc/fstab

Add a line for your SSHFS mount. The format is tricky and requires specific FUSE options:

user@remote_host:/remote/path /local/mountpoint fuse.sshfs _netdev,users,idmap=user,IdentityFile=/home/youruser/.ssh/id_rsa,allow_other,default_permissions,reconnect,auto_reconnect 0 0
user@remote_host:/remote/path /local/mountpoint fuse.sshfs _netdev,users,idmap=user,IdentityFile=/home/youruser/.ssh/id_rsa,allow_other,default_permissions,reconnect,auto_reconnect 0 0

Let’s break down the important options here:

Test the entry before rebooting:

sudo mount /local/mountpoint
sudo mount /local/mountpoint
sudo umount /local/mountpoint
sudo umount /local/mountpoint

Mounting at boot is powerful, but requires careful configuration and testing. Use it when you absolutely need the remote filesystem available immediately after startup.

SSHFS Gotchas: Common Pitfalls and How to Fix Them

Even seasoned pros bump into issues. Here are some common SSHFS problems and how to troubleshoot them:

Alternatives (Why SSHFS Might Be Your Jam)

While SSHFS is awesome, it’s not the only way to access remote files. You might encounter:

SSHFS strikes a great balance for secure, convenient, user-level mounting, especially over the internet or for accessing single directories without needing full system-level file sharing setup.

Conclusion: You’re an SSHFS Master Now!

You’ve done it! You’ve gone from potentially not knowing what SSHFS was to understanding its core concept, installing it, using basic commands, exploring powerful advanced options, and learning how to tackle common issues.

SSHFS is an invaluable tool in any Linux user’s kit, bridging the gap between your local machine and remote servers with elegance and security. Whether you’re managing files on a headless server, organizing a media library, or tweaking game server settings, SSHFS makes the remote feel local.

Start integrating it into your workflow. Begin with simple mounts, then explore the caching and reconnect options. When you’re feeling brave, tackle the fstab entry for your most-used remote folders.

Goodbye, constant scp prompts! Hello, seamless remote file access!


Share this post on:

Previous Post
Ventoy: Boot Any OS, Any Time
Next Post
Understanding and Optimizing Docker’s daemon.json File