SSH 安全最佳实践:从认证到隧道

概述 SSH(Secure Shell)是 Linux 运维的核心通道,也是攻击者的主要目标。一个配置不当的 SSH 服务可能导致服务器被完全接管。从认证机制、服务端硬化、跳板机架构、隧道技术、审计日志到暴力破解防护,全面覆盖 SSH 安全的好的实践。 密钥认证 生成密钥对 # 生成 Ed25519 密钥(推荐) $ ssh-keygen -t ed25519 -C "admin@sre.wang" -f ~/.ssh/id_ed25519 # 生成 RSA 密钥(兼容性需求,至少 4096 位) $ ssh-keygen -t rsa -b 4096 -C "admin@sre.wang" -f ~/.ssh/id_rsa # 生成带密码保护的密钥 $ ssh-keygen -t ed25519 -N "strong-passphrase" -f ~/.ssh/id_ed25519 # 查看密钥指纹 $ ssh-keygen -lf ~/.ssh/id_ed25519.pub 256 SHA256:abc123... admin@sre.wang (ED25519) 密钥算法对比 算法 密钥长度 安全性 性能 推荐 Ed25519 256 位 极高 极快 首选 RSA-4096 4096 位 高 中 兼容场景 RSA-2048 2048 位 中 快 不推荐 ECDSA 256/384/521 高 快 有争议(NIST 曲线) DSA 1024 位 低 - 已废弃 部署公钥 # 方式 1:ssh-copy-id(推荐) $ ssh-copy-id -i ~/....

December 12, 2023 · 11 分钟 · 2136 字 · 徐保金