nix-git/modules/ssh-server.nix

35 lines
1.1 KiB
Nix
Raw Normal View History

2023-09-16 12:14:53 +02:00
{ config, pkgs, ... }:
{
# Enable SSH server.
services.openssh = {
enable = true;
2023-09-23 18:36:27 +02:00
ports = (
2023-09-23 19:15:54 +02:00
if (config.networking.hostName == "yodaTux") || (config.networking.hostName == "yodaTab")
2023-09-23 18:36:27 +02:00
then [22]
2023-09-23 19:15:54 +02:00
else if (config.networking.hostName == "yodaYoga")
2023-09-23 18:36:27 +02:00
then [2224]
2023-09-23 19:15:54 +02:00
else if (config.networking.hostName == "yodaNas")
2023-09-23 18:36:27 +02:00
then [2222]
2023-11-03 15:23:05 +01:00
else if (config.networking.hostName == "yodaHedgehog")
then [2226]
2023-09-23 18:36:27 +02:00
else throw "Please add ssh port here"
);
2023-09-16 12:14:53 +02:00
# Use authorized keys only.
settings.PasswordAuthentication = false;
2023-09-17 15:34:38 +02:00
# Enabling this is required for commands such as sftp and sshfs.
allowSFTP = false;
2023-09-16 12:14:53 +02:00
};
# SSH public key(s) allowed to connect via SSH.
2023-11-03 15:23:05 +01:00
users.users."yoda".openssh.authorizedKeys.keys = [
2023-09-17 16:45:02 +02:00
(builtins.readFile ../assets/ssh/nitrokey.pub)
];
2023-11-03 15:23:05 +01:00
users.users."root".openssh.authorizedKeys.keys = [
2023-09-17 16:45:02 +02:00
(builtins.readFile ../assets/ssh/nitrokey.pub)
2023-09-27 20:12:19 +02:00
] ++ (
if (config.networking.hostName == "yodaNas")
2023-11-18 13:01:18 +01:00
then [(builtins.readFile ../assets/ssh/hedgehog.pub)]
2023-09-27 20:12:19 +02:00
else []
);
2023-09-16 12:14:53 +02:00
}