Diagnose an SSH Service That Stopped Accepting Connections
System DesignModel answerLast updated
Design a layered, evidence-driven diagnostic plan to find why an SSH daemon is unreachable, from the client all the way down to daemon logs.
Scenario
You are on call when a monitoring alert fires: a critical internal host, prod-exec-04.infra, is no longer accepting SSH connections. Engineers attempting to connect see either Connection refused or Connection reset by peer. Out-of-band access (IPMI or serial console) is still available, but all remote shell access is gone.
Walk through a complete, layered troubleshooting plan to pinpoint the root cause. For each step, describe the exact command or telemetry source you would use, the hypothesis it is testing, and — crucially — what the result conclusively proves versus what uncertainty remains.
What your answer should cover
1. Client and transport layer (outside-in)
- How do you distinguish between the three main failure signatures: silent timeout, an active TCP RST, and a reset that happens after the TCP handshake already completed?
- What client-side tools would you use (
ssh -vvv,nc,tcpdump,mtr/traceroute), and what does each failure mode rule out?
2. Host network and firewall layer (via console)
- How would you verify interface state, routing, and packet-filter rules (
iptables,nftables,firewalld)? - How do you tell apart a silent packet drop from an active reject at the firewall level?
3. Socket and process layer
- How do you confirm whether
sshdis running and what address/port it is bound to? - What would you check if the daemon exists but appears hung or is refusing new connections despite being technically alive?
4. Authentication and daemon logging
- Where do you look for log evidence once you have confirmed the daemon received the connection?
- What less-obvious configuration issues (TCP wrappers, PAM, SELinux/AppArmor, disk/inode exhaustion) could cause a connection that completes the TCP handshake to fail immediately after?
A strong answer states the hypothesis before each check, explains what the observation proves, and identifies the residual ambiguity. Listing tools without reasoning will not score well.
Hints
Hint 1
Start by pinpointing the exact error message. `Connection timed out`, `Connection refused`, and `Connection reset by peer` each point to a different layer — nail that down before touching the host.
Hint 2
A `tcpdump` on the host itself (accessed via console) is the single most decisive check in the whole procedure: if no SYN arrives, the problem is upstream; if a SYN arrives and a RST leaves, the host is rejecting it locally.
Hint 3
Don't forget the gap between 'sshd is running' and 'sshd can handle new connections' — fd exhaustion, listen-backlog overflow, a misconfigured `ListenAddress`, and a hung process in D-state can all make a running daemon effectively unreachable.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Core Strategy: Outside-In, One Layer at a Time
State a hypothesis, make a single observation, and record what it proves and what it leaves open. Never skip ahead. The most important early datum is the exact failure signature, because each one localises the fault to a different layer before you touch the host at all.
| Error seen by client | TCP wire behaviour | Layer implicated |
|---|---|---|
Connection timed out | SYN sent, nothing returns | Routing failure, firewall DROP, upstream ACL, host down |
No route to host | ICMP host/admin-unreachable returned | Firewall REJECT with ICMP, ARP failure |
Connection refused | RST returned (or ICMP port-unreachable) | No listener on that address/port, or firewall REJECT --reject-with tcp-reset |
Connection reset by peer / banner-then-close | TCP handshake completes, then RST/FIN before key exchange finishes | Daemon layer: TCP wrappers, MaxStartups, privsep directory missing, fd limits, PAM, SELinux |
One precision detail worth stating explicitly: on Linux, ICMP port unreachable surfaces to the caller as ECONNREFUSED. That means "refused" does not prove the remote kernel sent a RST — only a packet capture settles that.
Stage 1: Client and Transport (Outside-In)
Hypothesis: the fault may be purely network-side and never reach the host.
ssh -vvv prod-exec-04.infra— watch where the log stops. Stopping atconnect to address … port 22means L3/L4 failure. ReachingConnection establishedbefore failing means TCP succeeded and the daemon itself is involved.nc -vz -w3 prod-exec-04.infra 22— strips all SSH client config out of the picture. If you get a banner (SSH-2.0-OpenSSH_…), sshd is alive and its pre-auth path works.getent hosts prod-exec-04.infra— confirms DNS resolves to the IP you expect. Stale DNS or a recently re-assigned IP is a classic silent culprit.tcpdump -nn -i any host <ip> and port 22on the client — inspect the TTL on any returning RST. If the TTL doesn't match the host's expected value (e.g., 64 minus hop count), the RST came from a middlebox, not the host kernel.mtr -T -P 22 <ip>— shows where a TCP SYN to port 22 stops along the path; compare with a standard ICMP trace to isolate port-specific ACLs.- Test from a second client or a different subnet. A different result means the cause is source-specific: an ACL, a
hosts.denyentry, or fail2ban.
Residual ambiguity: client-side capture cannot definitively distinguish a host-kernel RST from a middlebox RST without TTL heuristics or corroborating evidence from the host side.
Stage 2: Host Network and Firewall (via Console)
Hypothesis: the host is up but silently dropping or actively rejecting packets before they reach sshd.
ip -br link && ip -br addr && ip route get <client-ip>— confirm the interface is UP, the expected IP is assigned, and the return path is symmetric. Also checksysctl net.ipv4.conf.all.rp_filter; strict reverse-path filtering with asymmetric routing silently drops traffic.tcpdump -nn -i <iface> port 22on the host — this is the single most decisive check. SYN arrives but RST leaves → host is rejecting locally. No SYN at all → problem is upstream, stop looking at the host.- Firewall rules:
nft list rulesetiptables-save -ctheniptables -L -n -v --line-numbers(watch counters increment while retrying)firewall-cmd --list-all- Check whether the system uses the nftables backend for iptables — rules can exist in one while you're inspecting the other.
- Drop vs. reject distinction: a
DROPproduces a silent timeout and nothing appears on egress. AREJECTproduces an RST or ICMP port-unreachable on egress and the matching rule's packet counter increments. ip netns list— confirm you are inspecting the right network namespace; containers running on the host may hold the listener in a separate namespace.
Stage 3: Socket and Process
Hypothesis: sshd is not listening, is listening on the wrong address, or is alive but unable to accept new connections.
ss -tlnp 'sport = :22'orlsof -nP -iTCP:22 -sTCP:LISTEN:- Nothing → kernel is sending the RST. Find out why the daemon is not up.
127.0.0.1:22only →ListenAddressis misconfigured.- Owner is
systemd→ socket activation (ssh.socket) is in use; check that unit too.
systemctl status ssh.socket sshd.serviceandsystemctl list-units 'ssh@*'.sshd -t— validates config syntax, host key permissions, and the existence of/run/sshd(missing privsep directory is a common crash cause after a failed upgrade).ps -o pid,stat,wchan:30,cmd -C sshd— aDstate means the process is blocked in an uninterruptible kernel wait (hung NFS mount, dead disk, blocked LDAP/NSS lookup).- fd exhaustion:
cat /proc/<pid>/limitsandls /proc/<pid>/fd | wc -l. Also checkcat /proc/sys/fs/file-nrfor system-wide fd pressure. - Listen-backlog overflow:
nstat -az TcpExtListenOverflows— this shows SYNs that were silently dropped because the accept queue was full, a subtle failure on high-traffic hosts. - Run a debug instance:
/usr/sbin/sshd -d -p 2222and connect to it. Full trace output, no production impact.
Stage 4: Authentication and Daemon Logs
Hypothesis: the daemon accepted TCP but is tearing down the session due to a configuration or environment error.
journalctl -u sshd -u ssh.socket --since -1h,/var/log/auth.log(Debian/Ubuntu),/var/log/secure(RHEL/Rocky).- TCP wrappers:
/etc/hosts.denycontainingsshd: ALLcauses the daemon to accept TCP and then immediately close it. The log line isrefused connect from. - PAM: look for
PAM unable to dlopenor brokenpam_access/pam_limitsentries. These typically surface after key exchange completes. - SELinux:
ausearch -m avc -ts recentandsestatus. A common case is sshd bound to a non-standard port that lacks thessh_port_tlabel, causing the bind to fail silently. - AppArmor:
dmesg | grep -i apparmor. - Disk and inodes:
df -h /var /runanddf -i. A full filesystem or exhausted inode count blocks PID files,/run/sshd, and writes tolastlog/wtmp, causing the daemon to abort or refuse new sessions. - Host keys:
Could not load host keyor zero-byte key files after a crash or botched update. Fix withssh-keygen -A.
Common Mistakes
- Reading logs first. If the daemon never received the connection, its logs are empty and you waste time.
- Assuming "refused" means no listener. As noted above, ICMP port-unreachable produces the same errno. A capture is required to be sure.
- Checking only
iptableson a system that uses nftables — or vice versa. - Missing the namespace. On a container host, the listener may be in a pod namespace and invisible to tools run in the host namespace.
Edge Cases Worth Mentioning
- IPv6/IPv4 resolution differences (
ssh -4/-6). - fail2ban or sshguard ban lists blocking a specific source IP.
Matchblocks insshd_configthat restrict access by source address.- Clock skew breaking GSSAPI/Kerberos authentication (only surfaces after the TCP session is fully established).
- A high-volume host where
MaxStartupsis set conservatively, causing sshd to probabilistically drop new connections under load.