tags:

views:

41

answers:

2

Hi, I would like to create script, which simply runs ssh-keygen -t rsa. But how to pass to it 3 times enter?

+5  A: 

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)

-f my.key tells it to store the key into my.key (change as you see fit).

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
Rudu
It is correct anwser, but i still would like to know how to press enter more then one time - in another script.
Sławosz
Sure thing - updated the answer to include how to send newlines to a script.
Rudu
echo -e "\n\n\n" | sshkeygen -t rsa is not working for me, can you try it yourself? It pass only first enter. But on other, simple script it works.
Sławosz
I tested it before I posted it - it works fine, although it looks like the dash from `ssh-keygen` got dropped - did you add that back in? {edited} Also - you can't run the script more than once - it changes the questions to confirm you want to overwrite the existing `_rsa` keyfile (so a y or n needs to be supplied)
Rudu
A: 

Use expect.

Dennis Williamson
That's completely unneeded here. See Rudi's answer.
Daenyth
Thanks, expect is great :D
Sławosz