Home Explore Blog CI



nixpkgs

1st chunk of `nixos/doc/manual/configuration/sshfs-file-systems.section.md`
f8775d353afc354f01f4bf386b4ebff4948c7dd5b6ccef6200000001000007f1
# SSHFS File Systems {#sec-sshfs-file-systems}

[SSHFS][sshfs] is a [FUSE][fuse] filesystem that allows easy access to directories on a remote machine using the SSH File Transfer Protocol (SFTP).
It means that if you have SSH access to a machine, no additional setup is needed to mount a directory.


## Interactive mounting {#sec-sshfs-interactive}

In NixOS, SSHFS is packaged as `sshfs`.
Once installed, mounting a directory interactively is simple as running:
```ShellSession
$ sshfs my-user@example.com:/my-dir /mnt/my-dir
```
Like any other FUSE file system, the directory is unmounted using:
```ShellSession
$ fusermount -u /mnt/my-dir
```

## Non-interactive mounting {#sec-sshfs-non-interactive}

Mounting non-interactively requires some precautions because `sshfs` will run at boot and under a different user (root).
For obvious reason, you can't input a password, so public key authentication using an unencrypted key is needed.
To create a new key without a passphrase you can do:
```ShellSession
$ ssh-keygen -t ed25519 -P '' -f example-key
Generating public/private ed25519 key pair.
Your identification has been saved in example-key
Your public key has been saved in example-key.pub
The key fingerprint is:
SHA256:yjxl3UbTn31fLWeyLYTAKYJPRmzknjQZoyG8gSNEoIE my-user@workstation
```
To keep the key safe, change the ownership to `root:root` and make sure the permissions are `600`:
OpenSSH normally refuses to use the key if it's not well-protected.

The file system can be configured in NixOS via the usual [fileSystems](#opt-fileSystems) option.
Here's a typical setup:
```nix
{
  fileSystems."/mnt/my-dir" = {
    device = "my-user@example.com:/my-dir/";
    fsType = "sshfs";
    options =
      [ # Filesystem options
        "allow_other"          # for non-root access
        "_netdev"              # this is a network fs
        "x-systemd.automount"  # mount on demand

        # SSH options
        "reconnect"              # handle connection drops
        "ServerAliveInterval=15" # keep connections alive

Title: SSHFS File Systems in NixOS
Summary
This section explains how to use SSHFS in NixOS to access directories on a remote machine using SFTP. It covers interactive mounting using the `sshfs` command, and non-interactive mounting at boot, emphasizing the need for public key authentication without a passphrase. It also details how to configure the file system using the `fileSystems` option in NixOS, including necessary options for network filesystems and SSH connections.