Post-Quantum GitHub/GitLab SSH on NixOS
tl;dr: NixOS configuration which passes the tests in Paul Bauer’s excellent Post-Quantum GitHub SSH for both GitHub and GitLab.
How do I use this?
The ultra-condensed version, once you’ve read and understood the article:
- Create an ecdsa-sha2-nistp384 key with
ssh-keygen -t ecdsa -b 384. -
Copy the NixOS system-wide SSH client configuration to your own. As a standalone Nix file:
{ config.programs.ssh.hosts = { "github.com" = { KexAlgorithms = "mlkem768x25519-sha256,sntrup761x25519-sha512"; order = 100; }; "gitlab.com" = { KexAlgorithms = "mlkem768x25519-sha256,sntrup761x25519-sha512"; order = 101; }; }; } -
Copy the Home Manager user-specific SSH client and Git configuration to your own. As a standalone file, where you have to replace the email and public key:
{ config.programs = { ssh.settings = { "Host github.com".IdentityFile = "~/.ssh/id_ecdsa"; "Host gitlab.com".IdentityFile = "~/.ssh/id_ecdsa"; }; git.settings.gpg.ssh.allowedSignersFile = toString ( pkgs.writeText "allowed_signers" '' your-email@example.com namespaces="git" your-new-public-key '' ); }; }If you don’t use Home Manager, edit your
~/.ssh/configto add the four lines corresponding to the linked diff, and~/.config/git/configto replace the path to your signature file. - Add the new public key to GitHub (twice, for both authentication and signing) and GitLab (once, for both authentication and signing).
- Apply the NixOS configuration.
At this point you should see four lines printed when running the below, indicating that both test commands succeeded on both hosts.
for host in github.com gitlab.com; do
ssh -v -o ControlPath=none -T "git@${host}" 2>&1 |
grep 'kex: algorithm: mlkem768x25519-sha256'
ssh -v -o ControlPath=none -T "git@${host}" 2>&1 |
grep "Server accepts key: ${HOME}/.ssh/id_ecdsa ECDSA"
done