如何非交互式运行 ssh-keygen 生成 SSH 密钥文件
问题:
如果你想使用 ssh-keygen 生成密钥文件,它会提示你输入密钥密码:
ssh-keygen-noninteractive.sh
$ ssh-keygen -t ed25519 -f id_ed255194
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):但对于脚本和自动化部署,你想避免提示并禁用密钥的密码加密。
解决方案
使用 -N "" 设置空密码:
ssh_keygen_noninteractive.sh
ssh-keygen -t ed25519 -f id_ed25519 -N ""例如:
ssh_keygen_example_output.txt
$ ssh-keygen -t ed25519 -f id_ed25519 -N ""
Generating public/private ed25519 key pair.
Your identification has been saved in id_ed25519
Your public key has been saved in id_ed25519.pub
The key fingerprint is:
SHA256:o/PVrBXpccLOjrVi6vfGWcmNtoubpINfrMxbz4EXtrU uli@uli-desktop
The key's randomart image is:
+--[ED25519 256]--+
| |
| |
| |
| . . |
| S *.++.|
| . . B B*+o|
| o ...#++E |
| o.+=%+B.. |
| .+=X*B.+. |
+----[SHA256]-----+Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow