How to execute ssh-keygen uninvited
I want to automate the generation of an ssh key pair using a shell script on Centos7 and I have tried
yes "y" | ssh-keygen -t rsa
echo "\n\n\n" | ssh-keygen...
echo | ssh-keygen..
this whole command doesn't work, just type one 'enter' and the shell script is stopped at "Enter passphrase (empty without passphrase)", I just want to know how to simulate mutiple 'enter' in the shell continuously.
Thanks a lot if anyone can help!
source to share
None of the answers do exactly what is expected. Behavior required: run ssh-keygen with default settings (for example, if we just hit Enter) without prompting for input.
Command to run:
yes '' | ssh-keygen -N >/dev/null
skip> / dev / null if you want to print the output.
Expalaination:
yes y spam that ssh-keygen takes literally and creates keys in $ PWD / y and $ PWD / y.pub. yes '' spam blank lines (Enter), which is what we want. Specifying the file with -f ~ / .ssh / id_rsa will fail if the .ssh directory does not exist. The -t rsa option is not required if rsa is the default type (we inject spam anyway). The passphrase is not read from standard input (which we spam), but directly from the keyboard, so nothing can intercept it. For this reason, you need to specify -N '' for an empty passphrase.
source to share