I would like to make an automated script that calls ssh-keygen
and creates some pub/private keypairs that I will use later on. In principle everything works fine with....
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q
...except that it asks me for the passphrase that would encrypt the keys. This make -at present- the automation difficult.
I could provide a passphrase via the command line argument -N thepassphrase
, so to keep the prompt from appearing.
Still I do not even desire to have the keys -additionally secured by encryption- and want the keypairs to be plaintext.
What is a (the best) solution to this problem?
The -q
option which supposedly means "quiet/silent" does still not avoid the passphrase interaction. Also I have not found something like this
ssh-keygen ... -q --no-passphrase
Please do not start preaching about or lecture me to the pro and cons of the "missing passphrase", I am aware of that. In the interactive form (not as a script) the user can simply hit [ENTER] twice and the key will be saved as plaintext. This is what I want to achieve in a script like this:
#!/bin/bashcommand1 command2 var=$(command3)
this should not stop the script and ask for password
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q
/tmp/sshkey
already exists one gets an overwrite prompt, though. This can be prevented via redirecting/closing stdin - e.g. via adding0>&-
. – maxschlepzig Feb 04 '18 at 19:05-f ~/.ssh/id_rsa
), and specify a passphrase (-N ''
). – x-yuri Apr 01 '21 at 23:06sudo -i -u $user_name ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N "" option requires an argument -- N
– openCivilisation Apr 05 '21 at 05:01ssh-keygen -t rsa -b 4096 -f "C:/temp/sshkey" -q -N '""'
(single quotes around a set of double quotes). While 2 sets of double quotes works in this specific case, it can cause issues when paired with additional arguments (such as empty comment/-C
e.g.ssh-keygen -t rsa -b 4096 -f "C:/temp/sshkey" -q -N '""' -C '""'
). – PotatoFarmer Jul 09 '21 at 02:43HOSTNAME=$(hostname) ; yes | ssh-keygen -t rsa -C "$HOSTNAME" -f "$HOME/.ssh/id_rsa" -P "" && cat ~/.ssh/id_rsa.pub
– ruevaughn Jan 10 '22 at 07:28--%
stops powershell of interpreting arguments as commands or expressions. The stop-parsing token – Janis Veinbergs Nov 24 '22 at 15:12