在 Linux 下使用 OpenSSL 时,“密钥备份”通常指 私钥、证书、以及相关的配置/密码 的妥善保存。下面按常见场景说明。
常见位置:
/etc/ssl/private/、/etc/pki/tls/private/cp /etc/ssl/private/example.key /backup/example.key.bak
⚠️ 私钥权限通常应为 600:
chmod 600 /backup/example.key.bak
cp /etc/ssl/certs/example.crt /backup/example.crt.bak
cat example.key example.crt > example.pem.bak
或分开打包:
tar czf openssl-backup.tar.gz example.key example.crt
openssl rsa -aes256 -in example.key -out example.key.enc
恢复:
openssl rsa -in example.key.enc -out example.key
cp example.csr /backup/example.csr.bak
cp /etc/ssl/openssl.cnf /backup/openssl.cnf.bak
✅ 使用加密存储(如 gpg、age、openssl enc)
✅ 备份到离线或异地介质
✅ 记录密钥密码(密码管理器)
✅ 定期验证备份可恢复
示例(gpg 加密):
gpg -c example.key
❌ 只备份证书不备份私钥
❌ 私钥权限过宽(如 644)
❌ 忘记私钥密码
❌ 备份在公网可访问目录
如果你能说明:
我可以给你更精确的备份命令。