Linux › Section L · Network file transfer and sharing › Topic L.3

SSHFS, NFS, and cloud storage

Between Linux machines, three approaches to sharing cover most needs: SSHFS for quick access over SSH, NFS for the traditional shared filesystem on a trusted network, and FUSE tools for mounting cloud storage. Each trades convenience, speed and security differently, and no single one has won.

Three ways to share between Linux machines

"File sharing with Samba" covered Windows; between Unix-like systems the usual choices differ. SSHFS needs nothing on the server beyond an SSH login, so it suits one person reaching their files on another machine. NFS, the Network File System, is the long-standing Unix standard for many clients sharing a server's directories, typically a file server or a NAS (network-attached storage) box on a local network. Cloud object stores, such as Amazon S3, can be mounted through user-space tools. The commands here follow the official manuals.

SSHFS: a filesystem over SSH

SSHFS is a FUSE filesystem. FUSE, Filesystem in Userspace, lets an ordinary program supply a filesystem to the kernel, so no kernel code is needed. sshfs opens an SSH connection, talks SFTP over it and shows the remote files at a local mount point. The form is sshfs [user@]host:[dir] mountpoint: sshfs ada@server:projects ~/remote mounts the projects directory in ada's remote home on ~/remote, and with :dir left out you get the whole home directory. Install the sshfs package first. As an ordinary user, unmount with fusermount -u ~/remote (fusermount3 -u on some systems); root can also use umount. Mount it as yourself, not as root, so that file ownership and permissions stay consistent.

Strengths and limits of SSHFS

SSHFS needs almost no setup. The server needs only SFTP enabled, which most SSH servers have by default, and any network where SSH works will do, including the open internet, because everything is encrypted. Key-based login from "Network servers and SSH" removes the password prompt. The costs are speed, because every operation pays for encryption and SFTP round trips, and weak support for many users sharing one mount. Its project page also says it has no active, regular contributors, though fixes and releases continue. It is ideal for editing a few remote files or browsing a server, not for a team's main file store.

NFS: the client side

Mounting an NFS export looks like any other mount, with server:path as the device. As root: mount -t nfs fileserver:/srv/share /mnt/share. The -t nfs can usually be left out, because mount recognises the colon form. The client tools come in nfs-common on Debian and Ubuntu and nfs-utils on Fedora and RHEL. The nfs(5) manual lists the options. If no version is given, the client tries NFS 4.2 first and negotiates down, and vers= forces one. NFSv4 needs only TCP port 2049, the one port a firewall must open for it. Mounts are hard by default, retrying for ever if the server vanishes; the manual warns that soft mounts, which give up, can silently corrupt data. A permanent entry goes in /etc/fstab, as in "Mounting filesystems and /etc/fstab".

NFS security

Classic NFS trusts the client. With the default sec=sys, the server accepts the user and group IDs that the client machine reports, so any machine whose root user is untrusted can claim to be anyone, and traffic is not encrypted. That is why NFS belongs on a trusted local network, with the server limiting which addresses may mount. Stronger protection comes from Kerberos, with the flavours sec=krb5 for authentication, krb5i adding integrity checking and krb5p adding encryption, but Kerberos needs a key distribution centre and careful setup. User IDs must also match across machines: if ada is UID 1000 on the client and 1003 on the server, her files will appear to belong to someone else.

Worked example: exporting a directory with NFS

Share /srv/share read-write with the 192.168.1.0/24 network. 1. Install the server: nfs-kernel-server on Debian or Ubuntu, nfs-utils on Fedora, then enable the service, nfs-server on Fedora. 2. Add one line to /etc/exports: /srv/share 192.168.1.0/24(rw,sync,no_subtree_check). No space may come before the parenthesis, or the options apply to the whole world instead of that network. 3. Read the options: rw allows writes, since the default is read-only; sync, the default, replies only after data reaches stable storage. root_squash is also on by default, mapping the client's root to an anonymous ID so that remote root cannot act as root on the server. 4. Run exportfs -ra to apply the file. 5. From a client, mount fileserver:/srv/share /mnt/share and test a write.

Mounting on demand

A machine that lists network filesystems in /etc/fstab can stall at boot if the server is down. An automounter avoids that by mounting a filesystem only when something first touches it. The traditional tools were the automount daemon, autofs, and the older amd; today systemd provides automount units. The simplest route is the fstab option x-systemd.automount, which makes systemd create the automount for that entry, so the first access to /mnt/share triggers the real NFS mount. Units in general were covered in "systemd units and unit files".

Cloud storage through FUSE

Cloud object stores such as Amazon S3 and Google Cloud Storage are reached through web APIs over TLS, so they work anywhere with an internet connection and the provider handles the hardware. They are far slower than LAN storage and are billed for storage and often for downloads. FUSE tools can present them as a directory. rclone, an open-source tool supporting dozens of providers, mounts a configured remote with rclone mount remote:path /path/to/mountpoint, and fusermount -u unmounts it. Its documentation warns that many applications need --vfs-cache-mode writes to work on such a mount. For scheduled copies to the cloud, rclone sync or rclone copy behave much like rsync.

Worked example: choosing a sharing method

Match each need to a tool, giving the reason. 1. You want to edit a few files in your home directory on a cloud server from your laptop: SSHFS, because SSH already works and the traffic is encrypted. 2. Ten Linux workstations in one office need the same project directories from a NAS: NFS, which is fast on a LAN and handles many clients, with exports limited to the office network. 3. The same office has Windows and Mac users too: Samba, since they speak SMB natively. 4. Nightly off-site copies of the NAS: rsync or rclone to cloud storage, satisfying the off-site part of the 3-2-1 rule from "Quick copies and rsync". 5. Check latency: none suits compiling a large program over the network.

Why there is no single answer

Network file sharing has never settled on one standard for small sites. Classic NFS is fast but weakly secured unless Kerberos is added, and Kerberos is real work to run. Systems designed around strong security and caching, such as the Andrew File System (AFS) from the 1980s, thrived at universities and large firms that already ran Kerberos, but not in small networks. Cloud storage sidesteps much of this, since TLS provides encryption without a Kerberos realm and FUSE keeps the client in user space. Expect to combine tools, each used where it fits.

Common mistakes to avoid

First, mounting SSHFS as root, which muddles ownership. Second, using NFS with default security across an untrusted network. Third, a space before the parenthesis in /etc/exports, which exports to everyone. Fourth, adding no_root_squash without a strong reason. Fifth, mismatched user IDs between NFS client and server. Sixth, soft NFS mounts for data that matters. Seventh, network mounts in /etc/fstab that hang the boot when the server is down, when x-systemd.automount would help.

Key takeaways

FUSE lets user-space programs provide filesystems. sshfs [user@]host:[dir] mountpoint mounts files over SSH with almost no setup, unmounted with fusermount -u; it is secure but slow. NFS mounts server:/path, defaults to the newest version both ends support, uses TCP port 2049 for NFSv4 and trusts client-reported IDs under sec=sys, so keep it on trusted networks or use Kerberos. Exports live in /etc/exports, applied with exportfs -ra; root_squash is the default. x-systemd.automount mounts on first use. rclone and similar FUSE tools mount cloud storage.

Flashcards

Flashcard

FUSE

Filesystem in Userspace: an ordinary program supplies a filesystem

Used by sshfs and rclone mount.

Test your understanding

Question 1 of 5

What does the remote server need for sshfs ada@server: ~/remote to work?

Question 2 of 5

Why is NFS with the default sec=sys risky across an untrusted network?

Question 3 of 5

An /etc/exports line reads /srv/share 192.168.1.0/24 (rw). What is wrong with it?

Question 4 of 5

A client's root user creates a file on a default NFS export. Who owns it on the server?

Question 5 of 5

A laptop lists an NFS share in /etc/fstab and hangs at boot when the server is away. Which change helps most?

← Previous topicNext topic →