Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating "enter" keypresses for bash script generating ssh keys

Tags:

bash

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

like image 769
Sławosz Avatar asked Sep 07 '10 14:09

Sławosz


People also ask

How do I generate SSH key automatically?

Generating a SSH keyFrom the SSH section, select Create SSH Key. In the Create SSH Key dialog, enter a Key Name and then select Create Key. The private and public SSH key pairs generate. When complete, Triton confirms that SSH keys have been successfully added to your account.

How do you send enter key in Expect script?

hence typing "\r" for "Enter" key action.


2 Answers

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 
like image 184
Rudu Avatar answered Oct 16 '22 20:10

Rudu


a version with passphrase is:

$ ssh-keygen -t rsa -b 4096 -C "comment" -P "examplePassphrase" -f "desired pathAndName" -q  
  • the -q is for silent

Source is http://linux.die.net/man/1/ssh-keygen

like image 41
Michel Marro Avatar answered Oct 16 '22 20:10

Michel Marro