Search code examples
shellssh-keysssh-keygen

Is it possible to generate a passphrase-less rsa key using a bash script?


How can I run ssh-keygen -t rsa in order to generate a passphrase-less rsa key without any user intervention (without having to manually press Enter 3 times)?


Solution

  • Per the manual, -f can be used to specify output filename, and -N to specify password; with both of those done, there is no further prompting from the user.

    Moreover, redirecting stdin from /dev/null ensures that any attempt to prompt (except directly from the TTY) will fail rather than hanging indefinitely.

    ssh-keygen -f outfile -N '' </dev/null