以下是CentOS上SSH性能优化的关键措施:
调整内核参数
修改/etc/sysctl.conf,优化网络性能:
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
执行sysctl -p生效。
优化SSH服务配置
编辑/etc/ssh/sshd_config:
UseDNS no。GSSAPIAuthentication no。Compression yes。ClientAliveInterval 60,ClientAliveCountMax 3。MaxStartups 10:30:60(格式:初始并发:最大并发:超时时间)。客户端优化
在~/.ssh/config中添加:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
启用多路复用(减少连接开销):
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
ControlPersist 4h
```。
密钥认证与安全增强
PubkeyAuthentication yes,PasswordAuthentication no。Ciphers aes128-ctr,aes256-ctr,MACs hmac-sha2-256。系统级优化
setenforce 0。yum update openssh-server。注意:修改配置前需备份文件,测试环境验证后再应用到生产环境。部分优化(如关闭SELinux)可能影响系统安全性,需根据实际需求权衡。