我想通过脚本创建SSH密钥
由于我还是要设置空密码,所以我想知道是否有我可以通过1个命令行输入空密码SSH密钥。
ssh-keygen -t rsa -b 4096 -C "temp@example.com"
ssh-keygen -t rsa -b 4096 -C "temp@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): tmp_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in tmp_rsa.
Your public key has been saved in tmp_rsa.pub.
The key fingerprint is:
SHA256:R1SEZr34y/4oBRTK3AieT4b8fw1PDG1kUekTfFuHoDA temp@example.com
The key's randomart image is:
+---[RSA 4096]----+
| . E o*+.=+o|
| o * B=..+.++|
| = B++...+ *|
| = .o .+ + |
| S .o. o .|
| o o= |
| .o..o |
| ..o. |
| oo.. |
+----[SHA256]-----+
我正在尝试使用1个命令行创建没有密码的tmp_rsa
文件。
关于如何执行该操作的任何方向都会有很大帮助!
答案 0 :(得分:2)
ssh-keygen
具有options,可在命令行上指定密码和输出文件:
-f 文件名
指定密钥文件的文件名。
-N new_passphrase
提供新的密码。
所以:
$ ssh-keygen -t rsa -b 4096 -C "temp@example.com" -N '' -f tmp_rsa
Generating public/private rsa key pair.
Your identification has been saved in tmp_rsa.
Your public key has been saved in tmp_rsa.pub.
The key fingerprint is:
SHA256:1S94g+i4SBQeqUwQ7uuEx2ZOfp+z8dR+jFBC4qVRj5Y temp@example.com
The key's randomart image is:
+---[RSA 4096]----+
|o. .. |
|.. .o o+ . |
| .. +. *E o . |
|.o o oo..o.o . |
| .o o Soo + . |
|.... o.. . o |
|.o* . o o..o |
|oB ....* .. o |
| .o...=o. .. |
+----[SHA256]-----+
$ ls
tmp_rsa tmp_rsa.pub