SSH 登录缓慢的定位与修复
SSH 能登录,但认证或 shell 启动要等几秒到几十秒。常见于反向 DNS、GSSAPI、PAM/LDAP、NFS home 或登录脚本。
ssh -vvv user@host
sshd -T | grep -E 'usedns|gssapi|pam|maxauthtries'
journalctl -u sshd --since '30 min ago'
服务端:
time getent hosts <client-ip>
time sshd -T >/dev/null
systemd-analyze blame
UseDNS yes 触发反向解析,DNS 慢或不可达。GSSAPIAuthentication yes 在无 Kerberos 环境超时。/etc/profile、/etc/motd 或用户脚本执行慢。UseDNS no,确认反向解析是否必要。GSSAPIAuthentication。nscd/sssd 缓存。ssh -vvv 看时间花在哪个阶段,不要盲目改配置。ssh — 客户端调试sshd — 服务端配置journalctl — 认证日志getent — 解析测试