Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically press Enter to continue in Bash

Tags:

bash

input

enter

I want to change RSA Keys to open ssh connections without any problems. It works fine, if I use this tutorial but I want to have it done in a bash script. Unfortunately I am asked to enter a passphrase (I want to enter nothing). How can I achieve to automatically press Enter three times in a row, when the script reaches this point?

This thread did not help, because I am not allowed to install new programs on my work PC and the echo | command trick seems only to work for one Enter. Also I need to enter "n" and Enter, if the procedure was already made, to not overwrite any files. How do i achieve that?

like image 783
modmoto Avatar asked Jun 25 '12 13:06

modmoto


2 Answers

If you just need to press Enter a bunch of times this will do it:

yes "" | command

For anything more complicated than that you might want to use expect as suggested in the other thread, which you can install in your homedir without root priviliges.

PS: Please avoid re-posting questions in the future. If you don't like an answer for some reason, just comment on it.

like image 113
smocking Avatar answered Nov 18 '22 05:11

smocking


If you want to just create ssh keys in a bash script without requiring any user input, you can specify arguments to ssh-keygen:

# rsa type (default), no passphrase, write to file id_rsa and id_rsa.pub
captain:~> ssh-keygen -t rsa -N "" -f id_rsa
Generating public/private rsa key pair.
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
fe:4a:82:08:0e:ab:b7:02:62:11:4d:3e:79:a4:d3:98 [email protected]
like image 4
mrb Avatar answered Nov 18 '22 04:11

mrb