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, lets get started ...
ContentsShow / Hide
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
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 firstname.lastname@example.org:/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,
email@example.com:/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, performance and conclusion
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.
- Average transfer speed between the laptop and PC over 10/100M Ethernet was nearly always above 10 MB/s .
- Transfer speed between the laptop and router over 10/100M Ethernet was fluctuating near 7 MB/s .
- 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.
- Enabling compression doesn't improve the transfer speed at all.
So why should one choose SSHFS over NFS or Samba ? Again, setup is very quick, it also adds a bit security. You might also want to password less SSH login to mount SSHFS directories quickly.
Have any suggestion or question about SSHFS ? Just leave a comment, I'll be happy to discuss about it.