The Computer Oracle

Running ssh-keygen without human interaction?

--------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--------------------------------------------------

Track title: CC F Haydns String Quartet No 53 in D

--

Chapters
00:00 Question
00:39 Accepted answer (Score 22)
01:07 Answer 2 (Score 21)
01:27 Thank you

--

Full question
https://superuser.com/questions/478798/r...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #ssh #debian #sshkeys

#avk47



ACCEPTED ANSWER

Score 22


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 mykey.pub.
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)




ANSWER 2

Score 21


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.




ANSWER 3

Score 0


Command that works without interactive input:

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""

Explanation:

-t rsa: Specifies the key type as RSA.
-b 4096: Sets the key size to 4096 bits.
-f ~/.ssh/id_rsa: Specifies the output file name and path. The default file name is id_rsa and the directory is ~/.ssh.
-P "": Specifies an empty passphrase.