From 97e61a071d950a107f99dd8578ed13f874463649 Mon Sep 17 00:00:00 2001 From: Matthias Treydte Date: Tue, 12 Oct 2021 12:21:53 +0200 Subject: [PATCH] nixos/ssh: take care not to accept empty host key files In case of a power loss shortly after first boot, the host keys gernerated by ssh-keygen could exist in the file system but have zero size, preventing sshd from starting up. This commit changes the behaviour to generate host keys if the file either does not exist or has zero size, fixing the problem on the next boot. Thanks to @SuperSandro2000 for figuring this out. --- nixos/modules/services/networking/ssh/sshd.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/ssh/sshd.nix b/nixos/modules/services/networking/ssh/sshd.nix index 192533e52de0..004b4f99670f 100644 --- a/nixos/modules/services/networking/ssh/sshd.nix +++ b/nixos/modules/services/networking/ssh/sshd.nix @@ -439,7 +439,7 @@ in mkdir -m 0755 -p /etc/ssh ${flip concatMapStrings cfg.hostKeys (k: '' - if ! [ -f "${k.path}" ]; then + if ! [ -s "${k.path}" ]; then ssh-keygen \ -t "${k.type}" \ ${if k ? bits then "-b ${toString k.bits}" else ""} \