CentOS SSH 登录慢,常见原因和对应解决办法如下,按出现频率从高到低给你:
SSH 默认会做反向 DNS 解析,网不通或慢就会卡。
解决方法:
vi /etc/ssh/sshd_config
修改或添加:
UseDNS no
然后重启:
systemctl restart sshd
vi /etc/ssh/sshd_config
设置:
GSSAPIAuthentication no
重启:
systemctl restart sshd
在你自己的电脑上:
vi ~/.ssh/config
加:
Host *
GSSAPIAuthentication no
ForwardX11 no
如果服务器有主机名:
hostname
在 /etc/hosts 里加上:
127.0.0.1 localhost localhost.localdomain
内网IP 你的主机名
有时是登录后执行脚本慢:
/etc/profile~/.bashrcpam_systemd)可临时注释测试。
客户端执行:
ssh -vvv user@ip
看卡在哪一阶段(DNS / auth / shell)。
UseDNS no
GSSAPIAuthentication no
基本能解决 95% 的 CentOS SSH 登录慢问题。
如果你愿意,可以把 ssh -vvv 卡住的那几行贴出来,我帮你精准定位。