PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

SSHFS - Mount remote folders in Linux over SSH

Updated - October 9, 2018 by Arnab Satapathi

Looking for a simple way to share files from your local or remote servers ?

Setting up NFS or Samba may not be so easy and quick, or not easily possible due to low system resources.

If you already have SSH access to the servers, setting up SSHFS will be like breeze, it needs almost zero server side configuration.

It depends on OpenSSH SFTP server on the server side and sshfs client on the other side, SSHFS is based on the FUSE file system, more here.

So In this mini tutorial we're going to mount remote folders in Linux with SSHFS and some more advanced tips, let's get started.

Contents

  • Install SSHFS
  • Mount remote folders with SSHFS
  • Automatically mount remote folders with SSHFS fstab entry
  • Testing and performance
  • Conclusion

Install SSHFS

Assuming you already have a working SSH setup on the server side, you need just another application there, a SFTP server.

Installing OpenSSH SFTP server is quite easy, almost every Linux distros have prebuilt packages for that.

In Debian or other Debian derivatives install the openssh-sftp-server package.

sudo apt-get install openssh-sftp-server

On OpenWrt, install the package is also openssh-sftp-server , so if you want SSHFS on OpenWrt, install it with opkg,

opkg update && opkg install openssh-sftp-server

Thankfully SSHFS works fine on OpenWrt with the default dropbear based ssh server.

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.

On the client side you need to install the SSHFS client, on Debian or other Debian derivatives like Ubuntu, Linux Mint install the sshfs package.

sudo apt-get install sshfs

That's all you need to install and configure for a basic setup.

Mount remote folders with SSHFS

Now the simplest usage of SSHFS, mount remote directory in Linux, the general syntax is like bellow,

sshfs user@host:/path/to/folder /path/to/mountpoint  <other options>

A simple example,

sshfs root@192.168.1.1:/mnt/sda1/ /home/user/sshfs/

Here the root is the SSH user's name on the server side and 192.168.1.1 is the server's IP address, you can use a hostname instead of IP address.

Also make sure that the both remote and local folders you're planning to mount with SSHFS exists.

The remote folder on the server /mnt/sda1 is mounted on /home/user/sshfs on the local machine, the folder /home/user/ is used just as an example.

SSHFS unmount: To unmount the mounded folders, the umount command works just fine.

sudo umount ~/sshfs

But experts recommends the fusermount command, this command doesn't need root privilege.

fusermount -u ~/sshfs

Automatically mount remote folders with SSHFS fstab entry

If you want to mount the remote folder permanently on a local system, you need to add a sshfs fstab entry.

Look at the example fstab configuration bellow,

user@192.168.10.101:/media/  /home/user/sshfs    fuse.sshfs defaults,_netdev,allow_other,users,IdentityFile=/home/user/.ssh/id_rsa    0    0

The above line is a bit long, better to copy-paste it somewhere for clear overview.

Note the IdentityFile mount option, that means you also need to setup key based SSH authentication. So if you're not so familiar with password less SSH login, here an easy tutorial.

A little about other options

  • _netdev , this option ensures that network access is available before trying to mount remote folders.
  • allow_other, other users can read-write inside the mounted folder, this option is useful for non-root users.
  • users, allow mount or unmount operations by other users than root.

You can check the man page for other available options, use the man sshfs command.

Testing and performance

You can use the mount command to check if the remote folder is mounted or not.

mount | grep 'sshfs'

Now about speed and performance, I've tested SSHFS with three devices, a laptop and an old PC both running Debian testing,  and a router running OpenWrt.

Unfortunately neither the PC nor the router have have a gigabit Ethernet NIC, so I can't test SSHFS transfer speed over gigabit Ethernet.

  1. Average transfer speed between the laptop and PC over 10/100M Ethernet was nearly always above 10 MB/s .
  2. Transfer speed between the laptop and router over 10/100M Ethernet was fluctuating near 7 MB/s .
  3. Transfer speed heavily degraded over wi-fi, (150Mbps b/g/n Atheros card), average transfer speed was around 1-2 MB/s between the laptop and router, it was also fluctuating heavily.
  4. Enabling compression doesn't improve the transfer speed at all.

Conclusion

So why should one choose SSHFS over NFS or Samba? Again, setup is very quick, it also adds some security.

You might also want to password less SSH login to mount SSHFS directories even more quickly without typing the password every time.

Have any suggestion or question about SSHFS ? Just leave a comment, I'll be happy to discuss about it.

Filed Under: how to, networking Tagged With: networking, shell

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap