Home » Linux » How do I run ssh-keygen so that it overwrites without prompting if a key cert exists? [closed]

How do I run ssh-keygen so that it overwrites without prompting if a key cert exists? [closed]

Posted by: admin November 29, 2017 Leave a comment

Questions:

So I have this scenario where a remote call will be made to a target machine. It’s possible that more than one call will be made to generate the ssh keys, in which case the script will hang as it requests for an overwrite (y/n).

Is there a proper way to request a non-interactive overwrite (or silently ignore) of keys if found?

There doesn’t seem to be a –force or –overwrite option in

man ssh-keygen

that I can find. Is there a rationale for having it function this way, or is this a bug I should report to the authors?

Any help is appreciated.

Answers:

You can work around this thusly:

echo -e  'y\n'|ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa

It will still output the prompt, but complete the process and
overwrite the file.