在CentOS系统中使用密码管理工具是保护敏感信息的关键措施。以下是分步骤的专业解决方案:
推荐企业级方案:
1. Bitwarden(开源/自托管方案)
- 支持端到端加密
- 提供CLI和浏览器集成
- 可通过bitwarden-cli
管理服务器密码
KeePassXC(本地存储方案)
keepassxc-cli
HashiCorp Vault(企业级方案)
# 安装基础依赖
sudo yum install -y epel-release
sudo yum install -y gpg2 pwgen git
# 配置防火墙(如使用网络方案)
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable --now docker
docker run -d --name bitwarden \
-v /bw-data/:/data/ \
-e ROCKET_TLS={certs="/ssl/cert.pem",key="/ssl/key.pem"} \
-p 443:80 \
vaultwarden/server:latest
# 修改PAM配置
sudo vi /etc/pam.d/system-auth
# 添加密码复杂度要求
password requisite pam_pwquality.so try_first_pass retry=3 minlen=12 difok=6 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1
# 使用cron定期更换密码
0 0 1 * * /usr/bin/pwgen -sy 16 1 | tee /root/new_pass.txt | passwd --stdin root
# 生成ED25519密钥对
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/prod_access
# 配置sshd强制密钥认证
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo yum install -y audit
sudo systemctl enable --now auditd
sudo auditctl -w /etc/shadow -p wa -k shadow_access
sudo ausearch -k shadow_access | aureport -f -i
# 使用GPG加密备份
tar czvf pw_backup_$(date +%F).tar.gz ~/.password-store
gpg --symmetric --cipher-algo AES256 pw_backup_*.tar.gz
# 需要先配置rclone
rclone copy pw_backup_*.tar.gz.gpg backup_remote:encrypted_backups/
通过以上方案,可构建符合等保2.0三级要求的密码管理体系。建议根据实际业务需求调整安全级别,高敏感环境应考虑使用物理隔离的密码管理设备。