依赖 GnuPG 与 Bash 环境,macOS 剪贴板需把 PWDSH_CLIP_CMD 设为 pbcopy;启用 Pepper 后其值不包含在备份中,丢失将无法仅凭口令解密;PWDSH_COMMENT 写入的是未加密注释,勿放敏感信息
pwd.sh
drduhMIT活跃维护用 Bash 和 GnuPG 对称加密管理密码与机密信息,把密钥库放在一个加密文件里,靠命令行完成增删查改,适合不想依赖图形界面或云端服务的人。
Manage secrets with Bash and GnuPG symmetric encryption
git clone https://github.com/drduh/pwd.sh
./pwd.sh w userName 20README 未说明
用 Bash 和 GnuPG 对称加密管理密码等文本密钥的轻量脚本
用 Bash 和 GnuPG 对称加密管理密码与机密信息,把密钥库放在一个加密文件里,靠命令行完成增删查改,适合不想依赖图形界面或云端服务的人。
核心能力
- 每个密钥存为随机命名文件,索引加密映射用户名
- 索引和密钥文件可脱离脚本直接用 GnuPG 解密
- 支持写入、读取、列出、随机生成密钥与用户名
- 按时间戳保留历史版本,默认读取最新版本
- 可打包 tar 备份并支持环境变量自定义存储与剪贴板
容易踩的坑
- v4Version 4最新正式版2026-08-24 · 2026-08-24 01:00 UTC
- Version materials with "v4" prefix to improve compatibility
- Improved output format, timestamped final and error message
- Remove chmod "lock" on exit - no meaningful benefit from it
- Menu option to generate username or password without saving
- Refactor functions for improved reliability and readability
Full Changelog: https://github.com/drduh/pwd.sh/compare/3.0...v4
- 3.0Version 32024-07-05 · 2024-07-05 01:17 UTC
查看更新说明
The third stable release of pwd.sh password manager with usability improvements, new features and configuration options (detailed in README).
Version 3.0 also addresses the following known issues:
- When creating passwords, having to read the password back after writing it (sometimes only to find it does not meet requirements). The password can now remain on the clipboard for the timeout duration before being saved. If the password is not compatible, just Control-C and generate a new one.
- Password generated with
gpgoften lacked special character diversity and did not meet website requirements. The character set is now a configurabletrsetting to increase password quality.
Changelist
- New pepper feature for adding additional entropy to passphrase, see Details for more information. Off by default.
- New option
daily_backup: create daily backup archive on write. Off by default. - New option
pass_copy: keep password on clipboard before write. Helps ensure the password meets requirements before committing. Off by default. - New option
pass_chars: specify characters to use for password. Default is all alphanumeric and some common allowed special characters. - Support for unencrypted comment in safe and index files. Off by default.
- Support for other clipboards (e.g., primary/control-v clipboard with
xclip) - Support for systems without clipboard: passwords will print to screen and clear after timeout.
- Generate username functionality.
- Generate password with
trinstead ofgpgto improve compliance with password requirements. - Reduce default password length 20->14 characters, remove maximum limit.
- Increase filename size 8->10 characters.
- Script exits are trapped for chmod cleanup, now
0000. - Less ambiguous output messages.
- Copy password to clipboard before unlocking safe.
- Re-order action list so Read is first.
- Error handling and readability improvements.
Full Changelog: https://github.com/drduh/pwd.sh/compare/2.0...3.0
- 3.0b1Version 3 Beta 1pre-release2024-03-24 · 2024-03-24 19:43 UTC
查看更新说明
Version 3 Beta continues with additional features and reliability improvements.
Currently in beta testing.
Changelog:
- New configuration options available - see README#Configure.
- Support for unencrypted comment in safe and index files. Off by default.
- Support for systems without clipboard: passwords will print to screen and clear.
- Script exits are trapped for chmod cleanup, now
0000. - Updated "Clearing password" message.
- Copy password to clipboard before unlocking safe.
- Re-order action list so Read is first.
- Minor error handling and readability improvements.
- 3.0bVersion 3 Betapre-release2024-03-10 · 2024-03-10 19:05 UTC
查看更新说明
The third release of pwd.sh features new usability features and improvements, specifically addressing:
- When creating passwords, having to read the password back after writing it (sometimes only to find it does not meet requirements). The password can now remain on the clipboard for the timeout duration before being saved. If the password is not compatible, just Control-C and generate a new one.
- Password generated with
gpgoften lacked special character diversity and did not meet website requirements. The character set is now a configurabletrsetting to increase password quality.
Currently in beta testing.
Changelog:
- New option
daily_backup: create daily backup archive on write. Off by default. - New option
pass_copy: keep password on clipboard before write. Helps ensure the password meets requirements before committing. Off by default. - New option
pass_chars: specify characters to use for password. Default is all alphanumeric and some common allowed special characters. - Generate password with
trinstead ofgpgto improve compliance with password requirements. - Reduce default password length 20->14 characters, remove maximum limit.
- Increase filename size 8->10 characters.
- Explicitly unset password variable after write.
- Minor code readability improvements.
- 2.0Version 22020-05-25 · 2020-05-25 21:53 UTC
查看更新说明
The second release of pwd.sh features many security and reliability improvements, and is a recommended upgrade. Compatible on Linux, OpenBSD, macOS.
Known Issues:
- Newer versions of macOS error with
tr: Illegal byte sequence- see issue #36
Changelist:
- Passwords are now encrypted as individual files, rather than all encrypted as a single flat file.
- Individual password filenames are random, mapped to usernames in an encrypted index file.
- Index and password files are now "immutable" using chmod while pwd.sh is not running.
- Read passwords are now copied to clipboard and cleared after a timeout, instead of printed to stdout.
- Use printf instead of echo for improved portability.
- New option: list passwords in the index.
- New option: create tar archive for backup.
- Removed option: delete password; the index is now a permanent ledger.
- Removed option: read all passwords; no use case for having a single command.
- Removed option: suppress generated password output; should be read from safe to verify save.
- Newer versions of macOS error with
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
pwd.sh is a Bash script to manage text secrets, such as passwords, using GnuPG.
Each secret is saved to a randomly-named file in a directory. An encrypted index maps usernames to secrets contained in files. Both the index and files can be decrypted directly with GnuPG - without pwd.sh.
Install
Download from Releases, or to use the latest version, clone the repository:
git clone https://github.com/drduh/pwd.sh
Or download the script directly:
wget https://raw.githubusercontent.com/drduh/pwd.sh/main/pwd.sh
Use
Run the script interactively using ./pwd.sh or symlink to a directory in PATH:
w- write (create) a secretr- read (access) a secretl- list secret names and pathss- generate a random secretu- generate a random usernameb- archive materials for backupv- print version informationh- print help text
Options can also be passed on the command line.
Create a 20-character secret for userName:
./pwd.sh w userName 20
Read secret for userName:
./pwd.sh r userName
Secrets are stored with an epoch timestamp for revision control and the most recent version is read by default. To list all secrets or read a specific version of a secret:
./pwd.sh l
./pwd.sh r userName@1574723600
Create a backup tar archive:
./pwd.sh b
Restore from backup:
tar xvf pwd*tar
Configuration
pwd.sh can be configured with environment variables as follows:
| Variable | Description | Default | Available options |
|---|---|---|---|
PWDSH_STORE | secret storage directory | v4-pwd.sh.secret | any valid string |
PWDSH_INDEX | index file name | v4-pwd.sh.index | any valid string |
PWDSH_CLIP_CMD | clipboard to use | xclip | pbcopy on macOS |
PWDSH_CLIP_ARG | arguments to pass to clipboard command | unset (disabled) | -i -selection clipboard to use primary (control-v) clipboard with xclip |
PWDSH_CLIP_OUT | secret output destination, will set to screen without clipboard | clipboard | clipboard or screen |
PWDSH_CLIP_SEC | seconds to clear secret from clipboard/screen | 10 | any valid integer |
PWDSH_COPY | copy secret to clipboard before write | unset (disabled) | 1 or true to enable |
PWDSH_COMMENT | unencrypted comment to include in index and secret files | unset | any valid string |
PWDSH_ECHO | character used to echo password input | * | any valid character |
PWDSH_LEN | default secret length | 20 | any valid integer |
PWDSH_CHAR | character set for secret | A-Za-z0-9!@#$%^&*()_+ | any valid characters |
PWDSH_BACKUP_NAME | backup archive file name | v4-pwd.sh.hostname.2026-12-31.tar | any valid string |
PWDSH_PEPPER | file containing Pepper | unset (disabled) | any valid file path |
See config/gpg.conf for recommended GnuPG options.
Also see drduh/Purse which integrates with YubiKey instead of using a passphrase to access secrets.
Pepper
The Pepper is an additional string appended to the storage passphrase to improve its strength. When the PWDSH_PEPPER option is set to a valid path, a secret value is generated and displayed once, then saved to the respective file.
The Pepper should be written down (for example, transcribed with passphrase.html or passphrase.txt template) and stored in a secure, durable location for backup.
This feature may enable use of a more memorable - and possibly weaker passphrase - for convenience, while still guarding backups against passphrase brute-force attempts (provided the Pepper is backed up separately).
The Pepper feature is opt-in and has no effect unless explicitly enabled.
[!IMPORTANT] The Pepper is not included in backup archives! Without the Pepper, secret storage will not be accessible with the passphrase alone!