优化运维场景下 SSH 连接速度,可以从网络、SSH 配置、系统参数、认证方式几个层面来做。下面按“见效快 → 进阶优化”的顺序整理。
SSH 默认会做反向 DNS 解析,常常很慢。
服务端 /etc/ssh/sshd_config:
UseDNS no
重启 sshd:
systemctl restart sshd
GSSAPIAuthentication no
客户端也可在 ~/.ssh/config:
GSSAPIAuthentication no
避免每次新建 TCP + 密钥交换。
客户端 ~/.ssh/config:
Host *
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
ControlPersist 10m
效果:
如果安全性要求不是极高(内网环境):
Ciphers aes128-ctr
MACs hmac-sha1
或使用较新的:
Ciphers chacha20-poly1305@openssh.com
ssh-copy-id user@host
并禁用密码登录(生产建议):
PasswordAuthentication no
ssh-keygen -t ed25519
比 RSA 快很多。
避免 DNS 超时:
/etc/hosts
192.168.1.10 server1
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.core.rmem_max=16777216
pssh / pdshansible + ControlPersisttmux + sshtime ssh user@host echo ok
ssh -v user@host
重点看卡在:
expecting SSH2_MSG_KEX_ECDH_REPLY → 网络Trying private key → 认证debug1: Connection established 后慢 → DNS✅ UseDNS no
✅ GSSAPIAuthentication no
✅ ControlMaster + ControlPersist
✅ 公钥 + ed25519
✅ 内网 hosts / 私有 DNS
如果你愿意,可以告诉我:
ssh -v 卡在哪一步我可以给你一套针对性配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。