Skip to content

initrd ssh: cp: cannot stat '/etc/secrets/initrd/ssh_host_ed25519_key': No such file or directory #84976

@sjau

Description

@sjau

Describe the bug
Nixos changed from Dropbear to OpenSSH in the initrd. While doing so it requires new keys and new options were add.

However following the instructions still fails to build.

To Reproduce
Steps to reproduce the behavior:

  1. I first generated a key at /root/initrd-openssh-key and added the following to the configuration.nix:
            hostKeys = [ "/root/initrd-openssh-key" ];
  1. Rebuilding failed with this error:
cp: cannot stat '/root/initrd-openssh-key': No such file or directory
  1. However that file exists:
ls -al /root/initrd-openssh-key 
-rwxr-xr-x 1 root root 227 Apr  4 07:18 /root/initrd-openssh-key
  1. Then I followed the instructions from the module file https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/initrd-ssh.nix :
      example = [
        "/etc/secrets/initrd/ssh_host_rsa_key"
        "/etc/secrets/initrd/ssh_host_ed25519_key"
      ];
 [...]
        <prompt># </prompt>ssh-keygen -t rsa -N "" -f /etc/secrets/initrd/ssh_host_rsa_key
        <prompt># </prompt>ssh-keygen -t ed25519 -N "" -f /etc/secrets/initrd/ssh_host_ed_25519_key

So I created the /etc/secrets/initrd folder and run the two commands, which resulted in:

ls -al /etc/secrets/initrd/
total 35
drwxr-xr-x 2 root root    6 Apr 11 07:39 .
drwxr-xr-x 3 root root    3 Apr 11 07:39 ..
-rw------- 1 root root  399 Apr 11 07:39 ssh_host_ed_25519_key
-rw-r--r-- 1 root root   91 Apr 11 07:39 ssh_host_ed_25519_key.pub
-rw------- 1 root root 2590 Apr 11 07:39 ssh_host_rsa_key
-rw-r--r-- 1 root root  563 Apr 11 07:39 ssh_host_rsa_key.pub
  1. I then added the following to my configuration.nix nix:
    boot.initrd.network = {
        enable = true;
        ssh = {
            enable = true;
            port = 2222;
#            hostECDSAKey = /root/initrd-ssh-key;
            hostKeys = [ 
                "/etc/secrets/initrd/ssh_host_rsa_key"
                "/etc/secrets/initrd/ssh_host_ed25519_key"
            ];
            authorizedKeys = [ "${mySecrets.auth_ssh_key1}" "${mySecrets.auth_ssh_key2}" ];
        };
        postCommands = ''
            echo "zfs load-key -a; killall zfs" >> /root.profile
        '';
    };

and rebuild again. This time it failed:

cp: cannot stat '/etc/secrets/initrd/ssh_host_ed25519_key': No such file or directory
builder for '/nix/store/pff2dr2i17mjsjavkg6icy5wfixjjlyb-extra-utils.drv' failed with exit code 1
cannot build derivation '/nix/store/i33w1h0asyc33yl1m5f1cl1wpif3xmf0-stage-1-init.sh.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/aqmbw803m7rb4k38lrvfj11zbs1pb81m-initrd-linux-5.4.30.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/zcqgphq575pzzjf7kf7dvcpj5v3zxbbg-nixos-system-subi-20.09pre220429.9b0d2f3fd15.drv': 1 dependencies couldn't be built
error: build of '/nix/store/zcqgphq575pzzjf7kf7dvcpj5v3zxbbg-nixos-system-subi-20.09pre220429.9b0d2f3fd15.drv' failed

Expected behavior
It should properly detect the file provided in the hostKeys.

Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

  • system: "x86_64-linux"
  • host os: Linux 5.5.13, NixOS, 20.09pre218613.ae6bdcc5358 (Nightingale)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.3
  • channels(hyper): "nixos-19.09pre185402.5eac339829b"
  • channels(root): "nixos-20.09pre220429.9b0d2f3fd15"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module: initrd-ssh.nix

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions