Ubuntu SSH性能优化方法
/etc/ssh/sshd_config文件,设置UseDNS no,重启SSH服务(sudo systemctl restart sshd)即可禁用此功能。/etc/ssh/sshd_config中的GSSAPIAuthentication no,重启服务生效。/etc/ssh/sshd_config,设置PermitRootLogin no和PasswordAuthentication no,强制使用密钥认证,提升安全性的同时加快登录速度。/etc/ssh/sshd_config中添加或修改以下参数:TCPKeepAlive yes(启用TCP keepalive)、ClientAliveInterval 60(客户端每60秒发送一次心跳包)、ClientAliveCountMax 3(允许3次无响应后断开连接),重启服务使配置生效。/etc/ssh/sshd_config中添加TcpWindowSize 32768(单位:字节),重启服务。aes256-ctr(对称加密,速度快)或chacha20-poly1305@openssh.com(适用于低性能设备)。在客户端~/.ssh/config中添加:Host * Cipher aes256-ctr。curve25519-sha256),减少密钥协商时间。在客户端配置中添加:Host * KexAlgorithms curve25519-sha256,ecdh-sha2-nistp256。Compression yes,或在命令行中使用ssh -C user@host(临时启用)。sshuttle(Python实现)或mosh(Mobile Shell,支持网络波动)工具。例如,sshuttle -r user@server 0/0可将本地流量转发到服务器,mosh user@host则自动适应网络变化。mosh(sudo apt install mosh),连接方式为mosh user@host。openssh-server、openssh-client)为最新版本,获取性能优化和安全补丁。使用sudo apt update && sudo apt upgrade命令更新。/etc/sysctl.conf中的网络参数,如net.ipv4.tcp_tw_reuse = 1(复用TIME_WAIT状态的连接)、net.core.rmem_max = 16777216(增大接收缓冲区),运行sudo sysctl -p使配置生效。/tmp目录)和不必要的软件包,释放磁盘空间,避免因磁盘I/O瓶颈影响SSH性能。使用sudo apt autoremove(删除无用软件包)、sudo apt clean(清理软件缓存)、bleachbit(图形化清理工具)等工具。