用 OpenSSL 加强 Linux 系统安全的实操清单
一 基础加固与更新
二 证书与 PKI 体系建设
openssl genpkey -algorithm RSA -out server.key -aes256openssl req -new -key server.key -out server.csropenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crtsudo certbot --nginx -d yourdomain.comsudo certbot --apache -d yourdomain.comopenssl verify -CAfile ca_bundle.crt server.crtopenssl ca -config openssl.cnf -gencrl -out crl.pemopenssl ca -config openssl.cnf -revoke badcert.crtopenssl pkcs12 -export -inkey server.key -in server.crt -out server.p12openssl pkcs12 -in server.p12 -nocerts -out server.key -nodes 与 openssl pkcs12 -in server.p12 -clcerts -nokeys -out server.crtsudo cp server.crt /etc/ssl/certs/ && sudo cp server.key /etc/ssl/private//etc/ssl/private/ 仅 root 可访问(如 600)三 配置安全的 SSL TLS
ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';ssl_prefer_server_ciphers on;ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;openssl s_client -connect yourdomain.com:443 -servername yourdomain.com -tls1_2curl -I https://yourdomain.comsudo systemctl restart nginx/apache2sudo ufw allow 443/tcp四 加密通信与数据保护
openssl s_server -www -key server.key -cert server.crt -port 4433openssl s_client -connect localhost:4433openssl enc -aes-256-cbc -salt -pbkdf2 -in plaintext.txt -out ciphertext.bin -pass pass:YourStrongPassopenssl enc -d -aes-256-cbc -salt -pbkdf2 -in ciphertext.bin -out plaintext.txt -pass pass:YourStrongPass五 审计监控与持续合规