优化运维中使用 SSH(Secure Shell) 的性能,可以从 连接效率、传输性能、配置调优、架构设计 等多个层面入手。下面按实用程度给你一套系统性建议。
在 ~/.ssh/config 中配置:
Host *
ControlMaster auto
ControlPath ~/.ssh/%r@%h-%p
ControlPersist 10m
效果:
✅ 非常适合运维批量操作和跳板机场景
避免多次输入密码和多次握手:
Host target
HostName 10.0.0.10
ProxyJump bastion
或命令行:
ssh -J bastion target
服务端 /etc/ssh/sshd_config:
UseDNS no
客户端也可加:
GSSAPIAuthentication no
减少登录卡顿。
避免密码交互:
ssh-copy-id user@host
避免重复输入密钥密码:
eval $(ssh-agent)
ssh-add
客户端 ~/.ssh/config:
Ciphers chacha20-poly1305@openssh.com,aes128-gcm@openssh.com
MACs umac-128-etm@openssh.com
说明:
chacha20-poly1305:CPU 弱时更快aes128-gcm:支持 AES-NI 的服务器更快⚠️ 不要关闭加密,只做算法调优
服务端 /etc/ssh/sshd_config:
TCPKeepAlive yes
ClientAliveInterval 60
系统层(可选):
sysctl -w net.ipv4.tcp_window_scaling=1
避免串行 SSH:
pssh / pdshansible(默认并发)tmux + 同步输入示例:
pssh -h hosts.txt -i "uptime"
❌ 错误方式:
for host in hosts; do ssh $host cmd; done
✅ 正确方式:
ControlPersistmosh user@host
优点:
⚠️ 不适合高安全环境
/etc/ssh/sshd_config:
LogLevel ERROR
避免日志 IO 成为瓶颈。
ssh -v user@host # 看卡在哪一步
time ssh host echo ok # 测延迟
重点关注:
✅ 必做:
⚠️ 按需:
如果你愿意,我可以:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。