pass (Password Store) 是符合 Unix 哲學的命令列密碼管理器:以 GPG 加密單一密碼檔案、存儲於目錄樹 (~/.password-store)、支援 Git 版控同步、提供 Bash/Zsh 自動補全。無圖形介面依賴,極適合伺服器、開發機、極簡主義者。本文涵蓋安裝、初始化、增刪改查、生成隨機密碼、剪貼板自動清除、多機同步完整流程。
| 發行版 | 安裝指令 |
|---|---|
| Debian/Ubuntu/Mint | sudo apt-get install pass |
| Fedora | sudo dnf install pass |
| CentOS/RHEL | sudo yum install epel-release && sudo yum install pass |
| Arch/Manjaro | sudo pacman -S pass |
啟用補全 (Bash/Zsh/Fish 均支援):
echo "source /etc/bash_completion.d/password-store" >> ~/.bashrc
source ~/.bashrc
# Zsh: source /usr/share/zsh/functions/Completion/Unix/_pass
# Fish: 內建完成
gpg --full-generate-key
# 選擇 (1) RSA/RSA, 4096 bits, 過期時間 0 (永久), 實名/Email/註釋, 設定保護密語 (主密碼)
pass init
# 例:pass init user@example.com
# 建立 ~/.password-store 目錄
| 操作 | 指令 | 說明 |
|---|---|---|
| 新增/編輯密碼 (互動輸入) | pass insert path/name | 支援多行輸入 -m,Ctrl+D 結束 |
| 生成隨機密碼並儲存 | pass generate path/name 20 | 20 字元,含符號;-n 僅英數 |
| 查看密碼 (終端顯示) | pass path/name | 需輸入 GPG 密語解鎖 |
| 複製到剪貼板 (45 秒自動清除) | pass -c path/name | 最安全方式,避免屏幕殘留 |
| 列出所有條目 | pass 或 pass ls | 樹狀顯示目錄結構 |
| 搜尋條目 | pass find keyword | 模糊匹配路徑/檔名 |
| 移除條目 | pass rm path/name | 確認後刪除 |
| 重命名/移動 | pass mv old new | 支援跨目錄 |
| 複製條目 | pass cp src dst | — |
| 顯示 Git 歷史 | pass git log | 倉庫已初始化 Git 時可用 |
~/.password-store/
├── email/
│ ├── gmail.com.gpg
│ ├── outlook.com.gpg
│ └── protonmail.com.gpg
├── finance/
│ ├── bank-a.gpg
│ └── paypal.gpg
├── server/
│ ├── aws-root.gpg
│ ├── github-token.gpg
│ └── vps-ssh.gpg
└── web/
├── github.com.gpg
└── twitter.com.gpg
搭配 Tab 自動補全,輸入 pass em 即可快速定位。
# 1. 初始化 Git 倉庫 (pass 會自動提交每次變更)
pass git init
# 2. 關聯遠端 (GitHub/GitLab/自建 Gitea,建議私有倉庫)
pass git remote add origin git@github.com:user/password-store.git
# 3. 推送
pass git push -u origin master
# 其他機器拉取
git clone git@github.com:user/password-store.git ~/.password-store
# 同步更新
pass git pull
pass git push
安全提醒:遠端倉庫**必須設為私有**;GPG 私鑰**勿上傳**,僅在各機器匯入私鑰後解密使用。