基于 pass 的标准 Unix 密码管理方案。
~/.password-store/ # GPG 加密的密码库
├── .gpg-id # GPG 密钥 ID
├── .git/ # Git 版本控制
├── llm/api-key.gpg # LLM API Key
├── postgres/ # 数据库密码
├── qq-mail/ # 邮箱授权码
└── weixin/ # 微信推送 ID
安全特性:
pass show <path> # 显示完整内容
pass show -c <path> # 复制到剪贴板 (45s 后清除)
pass insert <path> # 交互式输入
pass insert -m <path> # 多行内容 (如配置文件)
pass edit <path> # 编辑器打开
pass ls # 列出所有
pass find <keyword> # 搜索
pass rm <path> # 删除
pass mv <old> <new> # 重命名/移动
| 服务类型 | 路径示例 |
|---|---|
| ---------- | ---------- |
| LLM API | llm/api-key |
| 数据库 | postgres/ |
| 邮箱 | |
| 推送服务 | |
| 云服务 | |
API_KEY=$(pass show llm/api-key)
DB_PASS=$(pass show postgres/stock_market-password)
import subprocess
def get_credential(path: str) -> str:
result = subprocess.run(
["pass", "show", path],
capture_output=True, text=True
)
if result.returncode != 0:
raise RuntimeError(f"Failed to get credential: {path}")
return result.stdout.strip()
api_key = get_credential("llm/api-key")
# 1. 安装 pass
apt install pass # Debian/Ubuntu
brew install pass # macOS
# 2. 克隆密码库
git clone <私有仓库> ~/.password-store
# 3. 验证 GPG 密钥
gpg --list-keys
cd ~/.password-store
git add -A && git commit -m "Update credentials" && git push
建议配置 cron 或 hook 在 pass insert/pass edit 后自动提交。
pass insert -mgit pull 获取最新变更chmod 700 ~/.password-storepass show 输出共 2 个版本