我想创建脚本,这只是运行 ssh-keygen -t rsa。但如何传递给它3次输入?
ssh-keygen -t rsa
Try:
ssh-keygen -t rsa -N "" -f my.key
-N "" tells it to use an empty passphrase (the same as two of the enters in an interactive script)
-N ""
-f my.key tells it to store the key into my.key (change as you see fit).
-f my.key
my.key
The whole thing runs without you needing to supply any enter keys :)
To send enters to an interactive script:
echo -e "\n\n\n" | ssh-keygen -t rsa
a version with passphrase is:
$ ssh-keygen -t rsa -b 4096 -C "comment" -P "examplePassphrase" -f "desired pathAndName" -q
Source is http://linux.die.net/man/1/ssh-keygen
echo -e "\n"|ssh-keygen -t rsa -N ""
Agree with Michel Marro except that it needs some more: If the file already exists, it will still be interactive asking if it has to overwrite it.
Use the answer of this question.
yes y | ssh-keygen -q -t rsa -N '' >/dev/null
The redirection to null is necessary to silence the overwrite message.
It is recommended to use ed25519 for security and performance.
yes "y" | ssh-keygen -o -a 100 -t ed25519 -C "Bla Bla" -f /mypath/bla -N ""
here
-o OpenSSH key format instead of older PEM (needs OpenSSH 6.5+)
-o
-a Number of primality test while screening DH-GEX candidates
-a
-t Type of key (ed25519, RSA, DSA etc.)
-t
-f /mypath/bla The output file path and name
-f /mypath/bla
-N "" Use empty passphase
and yes "y" for no interaction.
yes "y"
It will generate two files
/mypath/bla /mypath/bla.pub
where the bla file is private and bla.pub is public.
bla
bla.pub