Move ssh config into nix

This commit is contained in:
2026-06-09 19:19:27 +00:00
parent 60531ed270
commit a659a07637
4 changed files with 44 additions and 36 deletions

View File

@@ -1,25 +0,0 @@
Host *
# Share SSH connection.
# If disabling, consider impact on ssh agent forwarding in screen
# sessions (see .ssh/rc file).
ControlMaster auto
ControlPath ~/.ssh/ctl/%r@%h:%p
ControlPersist 10m
# When a shared connection is broken (remote reboot), detect it faster.
ServerAliveInterval 11
ServerAliveCountMax 2
ConnectTimeout 10
AddKeysToAgent yes
#Host custom-host-with-xorg
# HostName custom-hostname
# User crate
# ForwardX11 yes
# ForwardX11Trusted yes
#Host always-changing-keys-dont-care
# StrictHostKeyChecking no
# UserKnownHostsFile=/dev/null
Include config.d/*

View File

@@ -1,11 +0,0 @@
#!/bin/sh
# When SSH-ing with agent forwarding enabled, this variable is set by sshd
# itself. However, an existing screen session that we attach to will not have
# its SSH_AUTH_SOCK environment variable updated, so we hardcode this path in
# .screenrc and create a symlink to keep it alive.
#
# It WILL break if two sessions are opened to a machine, and a newer one is
# terminated. ControlMaster in .ssh/config solves this problem by sharing the
# connection (and as a result, sharing SSH agent socket).
[ -n "$SSH_AUTH_SOCK" ] && ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock

View File

@@ -188,5 +188,49 @@
'';
};
programs.ssh = {
enable = true;
enableDefaultConfig = false;
includes = [ "config.d/*" ];
settings = {
"*" = {
# Share SSH connection.
# If disabling, consider impact on ssh agent forwarding in screen
# sessions (see .ssh/rc file).
ControlMaster = "auto";
ControlPath = "~/.ssh/ctl/%r@%h:%p";
ControlPersist = "10m";
# When a shared connection is broken (remote reboot), detect it faster.
ServerAliveInterval = 11;
ServerAliveCountMax = 2;
ConnectTimeout = 10;
AddKeysToAgent = "yes";
};
};
};
home.file = {
".ssh/rc" = {
executable = true;
text = ''
#!/bin/sh
# When SSH-ing with agent forwarding enabled, this variable is set by sshd
# itself. However, an existing screen session that we attach to will not have
# its SSH_AUTH_SOCK environment variable updated, so we hardcode this path in
# .screenrc and create a symlink to keep it alive.
#
# It WILL break if two sessions are opened to a machine, and a newer one is
# terminated. ControlMaster in .ssh/config solves this problem by sharing the
# connection (and as a result, sharing SSH agent socket).
[ -n "$SSH_AUTH_SOCK" ] && ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
'';
};
".ssh/ctl/.keep".text = "";
};
home.stateVersion = "25.11"; # never modify
}