Can't Connect to SSH Server

I have a home NixOS server and a NixOS laptop that I use as a client. I typically use the server to host game servers with docker. I have not been able to SSH into it for the last week (within my local network) and I am not sure why, it was working previously. The relevant section of my setup is as follows:

Server configuration.nix:

...
  networking = {
    firewall = {
      allowedTCPPorts = [ 22 <some game server ports> ];
      allowedUDPPorts = [ <some game server ports> ];
      enable = true;
    };
    hostName = "isaac-server";
  };
  programs.ssh.startAgent = true;
  services.openssh.settings.PasswordAuthentication = false;
  services.openssh.settings.PubkeyAuthentication = true;
  services.openssh.settings.LogLevel = "DEBUG";
  services.sshd.enable = true;
  services.xserver.enable = true;

Server /etc/ssh/sshd_config (generated from NixOS config):

AuthorizedPrincipalsFile none
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
GatewayPorts no
KbdInteractiveAuthentication yes
KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
LogLevel DEBUG
Macs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
PasswordAuthentication no
PermitRootLogin prohibit-password
PrintMotd no
PubkeyAuthentication yes
StrictModes yes
UseDns no
UsePAM yes
X11Forwarding no
Banner none
AddressFamily any
Port 22
XAuthLocation /nix/store/2mkdc7bn2viiwrc6kgxd08h6d7gkmy3p-xauth-1.1.3/bin/xauth
Subsystem sftp /nix/store/08zh1bw6ida8d3hxz4n6sz60k4bnn50g-openssh-9.7p1/libexec/sftp-server 
AuthorizedKeysFile %h/.ssh/authorized_keys /etc/ssh/authorized_keys.d/%u
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

When I try to connect from the client, I get this output:

$ ssh -vvv -i ~/.ssh/id_ed25519.pub isaac@<server-local-ip>
OpenSSH_9.7p1, OpenSSL 3.0.14 4 Jun 2024
debug1: Reading configuration data /home/isaac/.ssh/config
debug1: /home/isaac/.ssh/config line 3: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 5: Applying options for *
debug2: resolve_canonicalize: hostname <server-local-ip> is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/isaac/.ssh/known_hosts'
debug1: Control socket "/home/isaac/.ssh/master-isaac@<server-local-ip>:22" does not exist
debug3: channel_clear_timeouts: clearing
debug3: ssh_connect_direct: entering
debug1: Connecting to <server-local-ip> [<server-local-ip>] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
debug1: identity file /home/isaac/.ssh/id_ed25519.pub type 3
debug1: identity file /home/isaac/.ssh/id_ed25519.pub-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.7
kex_exchange_identification: read: Connection reset by peer
Connection reset by 192.168.1.126 port 22

I get the same error with ssh-copy-id, so I had to transfer the public key manually. It is on my authorized_keys on the server as well.

Any help would be appreciated :slightly_smiling_face:

Since you enabled DEBUG logs on sshd server, can you check it on the server? sudo journalctl -lu sshd. You may also want to change services.sshd.enable to services.openssh.enable, for consistency. Former is just an alias to latter.

Thank you, I didn’t know services.sshd.enable was just an alias. Definitely making that change now. My SSH seems to be working again, but it stops working more frequently than I’d like. I will check the logs if I run into issues again. I do remember not seeing my client’s connection attempts from the server logs when it was failing.