How to run ssh-keygen non-interactively to generate a SSH key file
Problem:
If you want to generate a key file using ssh-keygen
, it will prompt you for a key password:
$ ssh-keygen -t ed25519 -f id_ed25519´
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
For scripts and automated deployments, however, you want to avoid the prompt and disable the password encryption of the key.
Solution
Use -N ""
to set an empty password:
ssh-keygen -t ed25519 -f id_ed25519 -N ""
For example:
$ 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]-----+