用 openssl rand 生成强随机密码
用系统里现成的工具生成密码学安全的随机密码,不需要再装 pwgen 之类。
执行 `openssl rand -base64 24` 生成 24 字节(192 位)随机数的 base64 编码,即一个强密码。
01命令
命令
$ openssl rand -base64 2402作用说明
参数是熵的字节数而不是字符数:`-base64 24` 输出 32 个 base64 字符,携带 192 位熵,远超现代建议强度。目标场景不兼容 base64 的 `+/=` 字符时(部分 API、Wi-Fi 密码)用 `-hex 16`,或者接 `tr -d '/+=' | cut -c1-20` 修剪输出。由于取自操作系统 CSPRNG,适合生成 API 密钥、数据库密码和 JWT 密钥;GPG 那类密钥材料则应使用 `openssl genpkey` 生成。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- openssl(1) — rand subcommand for random data依据: Documents openssl rand num generating cryptographically strong pseudo-random bytes, with -base64/-hex encoding.
最后验证: 2026-09-17 · 分类: 安全与隐私