204 Commits
Author SHA1 Message Date
Tom Fitzhenry c571adaefb nixos/sshd: remove 'moduliFile' option, in favour of settings.ModuliFile
Per RFC42.

As a result, /etc/ssh/moduli will no longer exist, and sshd_config's ModuliFile will point to /nix/store/...
2026-07-17 20:30:51 +10:00
Ryan Burns ef4ab8eaaa nixos/sshd: accept path-typed options
When the 'banner' option was removed in favour of settings.Banner,
it was made a path-typed option, but the current mkValueString doesn't
accept path-typed values so assigning a file to this option results in:
`error: unsupported type path: <store path>`

By adding the appropriate handling for mkValueString, this works as
expected.
2026-06-01 12:18:30 -07:00
Tom Fitzhenry 667a124021 nixos/sshd: remove 'banner' option, in favour of settings.Banner 2026-04-17 21:46:16 +10:00
Tom Fitzhenry 41c383338e nixos/sshd: add enableRecommendedAlgorithms option
Prior to this commit, NixOS enabled a set of curated algorithms.

This commit allows users to opt-out of this curation, and instead use
the upstream algorithms. This also allows users to set
Ciphers/KexAlgorithms/Macs themselves without lib.mkForce (and thus
wield NixOS modules to build the list).

Tests have been added to ensure test this new option works.
2026-04-13 01:03:11 +00:00
nikstur 4aae99b7d7 nixos-init: init env-generator
The env generator allows us to declaratively set environment variables
via the module system for all systemd generators.

This will allow us to drop systemd/0013-inherit-systemd-environment-when-calling-generators.patch
2026-02-13 00:05:41 +01:00
MartinandSefa Eyeoglu 63b76d59cd sshd: Document dhcp requirement for listenAddress
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2026-02-07 11:43:38 +01:00
SandroandGitHub 1cd4bfc5a3 nixos/sshd: fix sshd.conf check referencing package's extra outputs (#479779) 2026-02-01 20:14:38 +00:00
quantenzitrone 3e622a5110 nixos: remove references to the xorg namespace
this only creates the usual nixos module rebuilds
2026-01-25 22:58:40 +01:00
Dyego Aurélio 28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03:00
Edwin Mackenzie-Owen 9e3cf59268 nixos/sshd: fix sshd.conf check referencing package's extra outputs
The check derivation only needs the `sshd` binary (which is in the
regular `out` output) and has no need for the validationPackage's other
outputs that contain header files and man pages.

But when the validationPackage is added to the check derivation's
nativeBuildInputs, the latter references all outputs of the former, or
it at least requires the `dev` output to be present at build time.

This means that these outputs always need to present when rebuilding the
system, even when making changes completely unrelated to SSH.

Because the derivations in `system.checks` are only a build time
dependency of the system derivation but are not added to the system's
runtime closure, and a NixOS configuration otherwise only references its
ssh package's `out` output; the other outputs required at build time may
be garbage-collected from the system at any time [^1][^2].

In the best-case scenario, this only results in the download of
unnecessary store paths from a binary cache.

Other scenarios present larger issues:
- when using a custom package, the entire derivation has to be rebuild
  (recompilation) just to get the dev output back
  - even when the custom package or the system derivation containing it
    is stored on a binary cache, it won't have the output unless build
    time dependencies are pushed to it as well [^3].
- when there's no binary cache available (e.g. no internet connection),
  it might be impossible to rebuild the derivation because of other
  missing build time dependencies
  - again, the changes triggering a new NixOS build can be unrelated to
    SSH and might in themselves not requrie fetching any new store paths
    (e.g. updating a simple config file)

[^1]: Unless `keep-outputs = true` is set in nix.conf, but that is a
      non-default setting and affects the garbage-collection of other
      paths as well
[^2]: There's also the case that the validationPackage is a different
      package than the system's SSH package due to cross-compilation,
      in which case this fix wouldn't do much because even the `out`
      output is not part of the system closure.
[^3]: Users would have to know about it, but it's probably not desirable
      in most cases
2026-01-13 19:52:24 +01:00
Yuxuan Shui 14f52d1bd0 nixos/sshd: add AcceptEnv as an option
Allow other modules and the user to specify AcceptEnv without
conflicting with each other.
2025-12-16 01:06:12 +00:00
MynacolandMynacol 3194d1c498 nixos/sshd: Allow UsePAM being null
This commit allows setting the `UsePAM` setting to null. Without it, nix
fails to evaluate with:
```
error: ‘mkIf’ called with a non-Boolean condition
```

Setting it to null means no line for `UsePAM` is written into the
resulting sshd config file. This is needed if openssh is compiled
without PAM support. Otherwise the following log message is produced:
```
rexec line 15: Unsupported option UsePAM
```

This also adds the nixos test openssh-null-pam to set `UsePAM` to null.
This also tests that the above log line is not produced in that case.
2025-12-06 20:36:15 +01:00
Adam Dinwoodie 375fc85aea nixos/sshd: add generateHostKeys setting
If a user doesn't want to enable the SSH daemon, but does want to have
SSH host keys configured for some other reason (e.g. they're used for
host identification in some other way), provide a `generateHostKeys`
setting that will generate the keys without otherwise setting up sshd.
2025-12-05 09:47:34 +00:00
Philip TaronandGitHub 01898764b6 treewide: replace "yes" else "no" usages to lib.boolToYesNo (#442387) 2025-10-28 16:25:46 +00:00
Aliaksandr 80f12557f5 treewide: replace "yes" else "no" usages to lib.boolToYesNo 2025-10-21 16:04:34 +03:00
Aliaksandr f28be96fda treewide: mkAliasOptionModuleMD -> mkAliasOptionModule 2025-10-21 15:42:47 +03:00
7ebfdde615 nixos/ssh: fewer empty lines in generated ssh and sshd config files
Co-authored-by: r-vdp <ramses@well-founded.dev>
Co-authored-by:  Marie <tabmeier12@gmail.com>
2025-09-22 01:03:25 +02:00
Haylin Moore cf540f8c98 treewide/nixos: move number typed port options to types.port 2025-09-08 15:27:19 +02:00
Philip TaronandGitHub d392f98f00 services.openssh: use notify-reload for sshd (#427620) 2025-07-25 16:02:49 -07:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
ssoss edadf6cc0f services.openssh: use notify-reload for sshd 2025-07-23 01:24:58 +00:00
Yarny0 6acf53f654 nixos/sshd: don't use -a (KDF rounds) on host keys
The nixos `sshd.nix` module contains a
mechanism to generate ssh host keys prior to
starting sshd if those host keys are missing.
The option `services.openssh.hostKeys` is used to
configure which host keys should exist or be created.
It also declares the key type and other key-related options.

One of those options is `rounds`.
That one is then forwarded to the
`ssh-keygen` program with the `-a` option.
It defines how many rounds of a key derivation function
are to be used on the key's passphrase before the result
is used to en-/decrypt the private key; cf. ssh-keygen(1).

ssh host keys are passwordless;
they are solely protected by filesystem access modes.
Hence, the `-a` option is irrelevant
and silently ignored by `ssh-keygen`.

The commit at hand therefore removes this option from
the host key generation script and the option examples.
2025-06-09 21:06:20 +02:00
Peder Bergebakken Sundt c77ac9dfc3 treewide: fix typos 2025-06-02 16:07:07 +02:00
Silvan Mosberger e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Will FancherandGitHub bbf66d50a2 Fix systemd-ssh changes (#390565) 2025-03-17 05:21:36 -04:00
Will Fancher 4dcde98327 nixos/sshd: Fix socket activated SSH connections entering failed state.
In afeb76d628, sshd.service and
sshd@.service were switched to Type=notify. This apparently works for
sshd.service, but not for sshd@.service. Given that the reason for
this working with sshd.service isn't exactly clear, let's revert it
for both of them for now, and revisit Type=notify later.
2025-03-16 23:02:22 -04:00
Philip TaronandGitHub f4dd3ba6e0 systemd: make systemd-ssh-generator work (#372979) 2025-03-15 21:59:59 -07:00
Marie Ramlow 0ea1aedc4d nixos/sshd: enable root ssh authorized_keys provisioning
This enables provisioning of root ssh keys with systemd credentials
(e.g. passed in via smbios strings or kernel params)
2025-03-15 20:15:44 +01:00
Marie Ramlow afeb76d628 nixos/sshd: always ship a sshd@.service unit for systemd-ssh-generator(1) 2025-03-14 18:34:50 +01:00
Marie Ramlow 63842ed333 nixos/sshd: move key generation into its own systemd unit 2025-03-14 18:34:50 +01:00
6cd88104d7 nixos/openssh: allow post-quantum KexAlgorithms introduced in v9.9 (#378875)
`mlkem768x25519-sha256` and the vendor-neutral `sntrup761x25519-sha512`
name are new in OpenSSH 9.9 <https://www.openssh.com/txt/release-9.9>

Co-authored-by: Mynacol <Mynacol@users.noreply.github.com>
2025-02-19 22:04:03 +01:00
Peder Bergebakken Sundt 953f72e76e nixos/*: tag manpage references 2025-01-27 02:47:01 +01:00
K900andGitHub 099cde3a92 Revert "nixos/ssh: disable authorizedKeysInHomedir by default" 2024-10-20 21:32:29 +03:00
nicoo 6c62fbf539 nixos/sshd: warn if no authorized keys, and no authentication method other than pubkeys, were configured 2024-10-18 20:23:02 +00:00
nicooandValentin Gagarin 1f08575e3a nixos/sshd: Disable authorizedKeysInHomedir if stateVersion >= 24.11
Co-authored-by: Valentin Gagarin <valentin@gagarin.work>
2024-10-18 20:21:12 +00:00
r-vdp 342b5a8b85 sshd: fix shellcheck warnings in prestart script 2024-09-08 12:24:00 +02:00
Felix Buehler 5f8696e39c nixos/services.openssh: remove with lib; 2024-09-02 22:31:36 +02:00
Sigmanificient e959525e15 lsh: drop 2024-08-20 12:02:12 +02:00
Thomas Gerbetandtomf ef6fea2d86 openssh: move Kerberos support into a dedicated package
The `openssh` and `openssh_hpn` packages are now built without
the Kerberos support by default in an effort to reduce the attack surface.

The Kerberos support is likely used only by a fraction of the total users
(I'm guessing mainly users integrating SSH in an Active Directory env) so
dropping it should not impact too many users. It should also be noted that
the Kerberos/GSSAPI auth is disabled by default in the configuration.
`opensshWithKerberos` and `openssh_hpnWithKerberos` are added in order
to provide an easy migration path for users needing this support.

The `openssh_gssapi` package is kept untouched.
2024-06-05 19:45:31 +10:00
lassulusandGitHub d6f07be682 Merge pull request #314889 from DavHau/pr_sshd
nixos/openssh: allow removing settings
2024-05-30 01:01:07 +02:00
Thomas GerbetandGitHub 00015f3ef9 Merge pull request #309036 from tomfitzhenry/sshd-package
nixos/ssh: add services.openssh.package
2024-05-27 09:40:31 +02:00
DavHau 3fe773a174 nixos/openssh: allow removing settings
# Motivation
So far it was not possible to configure sshd to allow password authentication only for a specific user. This is because in the generated config a `Match User xxx` section would be required before the global `PasswordAuthentication` is defined, as otherwise the global option always takes precedence.
The same problem occurs with multiple other options under `settings`.

# Done
This PR fixes that issue for all settings by simply allowing them to be overridden with `null`, which leads to a removal of that setting from the config.
The user can then correctly configure user specific settings using extraConfig, like this:
```
    Match User user1
    PasswordAuthentication yes
    Match all
    PasswordAuthentication no
```
2024-05-26 18:46:27 +02:00
nicooandGitHub db5f88c41a nixos/ssh: Make ~/.ssh/authorized_keys optional in AuthorizedKeysFiles (#279894) 2024-05-06 01:11:03 +00:00
Tom Fitzhenry ff1c82ee07 nixos/ssh: add services.openssh.package
Motivation: Allow the sshd package to be built differently to the ssh
package (programs.ssh.package). For example, build sshd(1) without
openssl, but built ssh(1) with OpenSSL support.

Set the default to be programs.ssh.package, to preserve compatibility.
2024-05-04 23:14:47 +10:00
Tom Fitzhenry 3fd9ef4b40 nixos/ssh: allow PrintMotd to be enabled 2024-04-23 22:53:09 +10:00
Tom Fitzhenry 2e51a2fd03 nixos/ssh: allow UsePAM to be disabled 2024-04-23 22:40:58 +10:00
stuebinmandJonathan Ringer 6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Maximilian Bosch 7e45990c06 nixos/sshd: fix socket activated ports when using ListenAddress
Noticed that issue while reviewing #275633: when declaring
`ListenAddress host` without a port, all ports declared by
`Port`/`cfg.ports` will be used with `host` according to
`sshd_config(5)`.

However, if this is done and socket activation is used, only a socket
for port 22 is created instead of a sockets for each port from
`Port`/`cfg.ports`. This patch corrects that behavior.

Also added a regression test for this case.
2024-01-03 19:42:45 +01:00
Bryan Richter e797aaea0b sshd: Use top-level ports in config check when needed
Previously, if a listenAddress was specified without a `port`, the check
would fail.
2024-01-02 12:51:39 +02:00