Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Would it be possible to run ssh-keygen without human interaction?

I have a shell script that takes care of server deployment from start to finish, but ssh-keygen is the only remaining piece that still requires my input.

Would it be possible to feed the parameters to it? Or is there something similar to debconf-set-selections that could be used for this?

*running Debian

share|improve this question

migrated from Sep 24 '12 at 6:26

This question came from our site for professional and enthusiast programmers.

up vote 9 down vote accepted

You can do more or less anything with command-line arguments. Is there something particular you want to do which doesn't appear in the man page?

wry@onyx:~$ ssh-keygen -t dsa -N "my passphrase" -C "test key" -f mykey
Generating public/private dsa key pair.
Your identification has been saved in mykey.
Your public key has been saved in
The key fingerprint is:
2f:17:a4:5d:6f:25:d7:5a:0e:84:be:af:ee:52:8b:42 test key

(the rest snipped for brevity)

share|improve this answer
Best to avoid storing this command in your history - you don't want the passphrase recorded in plaintext on your computer. (Yes, generally the history file has 600 permissions so only root could snoop, but better safe than sorry.) – Jefromi Mar 28 '10 at 20:26
The point is he's going to script it anyway. – Joshua Sep 5 '12 at 18:14
In your script, use a prompt (read -s) to read the password to pass on. Also beware ps may reveal process command args (which will include password). Because of that it may be best to use expect along with the normal password prompt, to send it in that way. – Steven Lu Jul 19 '13 at 19:09
operacao@ubuntu:~$ ssh-keygen -t dsa
share|improve this answer
This does ask at least where to save the key. – spacediver Jan 18 '14 at 5:19

In case of server deployment:

ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""

In terms of communication from server installed to git repositories or other servers would be easy.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .