使用命令ssh-keygen 需要手动敲击回车,才会生成密钥,如下代码所示
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:liDdKl+uW9TmA++L3uoO99l/mFNRBP77bm/DbDuLHB4 root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| .o.|
| . . . .|
| . o . . .|
| . o o o |
| . . S o o|
| o = = o|
| o + + Eo= |
| = = +o B*=|
| o=*.*..=oOX|
+----[SHA256]-----+
但是有些场景,例如shell脚本中,需要自动生成密钥并自动 ss