12.5 SSHFS
With Windows file sharing systems out of the way, in this section we’ll discuss file sharing between Linux systems. For scenarios that aren’t particularly complicated, a convenient option to consider is SSHFS. This is nothing more than a user-space filesystem that opens an SSH connection and presents the files on the other side at a mount point on your machine. Most distributions don’t install it by default, so you might need to install your distribution’s SSHFS package.
The syntax for using SSHFS on the command line looks superficially similar to SSH commands that you’ve seen before. Of course, you need to supply the shared directory (on the remote host) and the desired mount point:
$ sshfs username@host:dir mountpoint
Just like in SSH, you can drop the username@ if the username is the same on the remote host, and you can also omit :dir if you just want to mount the home directory on the other side. This command asks for the password on the other side if necessary.
Because this is a user-space filesystem, you have to unmount it with fusermount if you’re running this as a regular user:
$ fusermount -u mountpoint
The superuser can also unmount these filesystems with umount. To ensure consistency of ownership and security, this type of filesystem is usually best mounted as a regular user.
SSHFS has these advantages:
- It has minimal setup. The only requirement on the remote host is that SFTP is enabled, and most SSH servers enable it by default.
- It’s not dependent on any kind of specific network configuration. If you can open an SSH connection, SSHFS will work, regardless if it’s on a secure local network or over an insecure remote network.
The disadvantages of SSHFS are:
- Performance suffers. There is a lot of overhead in encryption, translation, and transport (but it may not be as bad as you expect).
- Multiuser setups are limited.
It’s definitely worth trying SSHFS if you think it might work for you, because it’s so easy to set up.