nix-config/nixos/_mixins/services/openssh.nix

41 lines
1 KiB
Nix
Raw Normal View History

{ lib, config, ... }:
2023-09-26 17:44:54 +00:00
let
# Sops needs acess to the keys before the persist dirs are even mounted; so
# just persisting the keys won't work, we must point at /persist
hasOptinPersistence = config.environment.persistence ? "/persist";
in
{
services = {
openssh = {
enable = true;
settings = {
2023-09-26 17:44:54 +00:00
# Harden
PasswordAuthentication = false;
PermitRootLogin = lib.mkDefault "no";
2023-09-26 17:44:54 +00:00
# Automatically remove stale sockets
StreamLocalBindUnlink = "yes";
# Allow forwarding ports to everywhere
GatewayPorts = "clientspecified";
};
2023-09-26 17:44:54 +00:00
hostKeys = [{
path = "${lib.optionalString hasOptinPersistence "/persist"}/etc/ssh/ssh_host_ed25519_key";
type = "ed25519";
}];
};
sshguard = {
enable = true;
whitelist = [
2023-09-26 17:44:54 +00:00
# TODO
"192.168.40.0/24"
"10.0.0.0/8"
"100.0.0.0/8"
];
};
};
2023-09-26 17:44:54 +00:00
networking.firewall.allowedTCPPorts = [ 22 ];
2023-09-26 17:44:54 +00:00
# Passwordless sudo when SSH'ing with keys
2024-06-06 15:17:28 +00:00
security.pam.sshAgentAuth.enable = true;
}