0

Is there any way to create private and public keys with one command? The classic way is two commands

$openssl genrsa -out privkey.pem 2048

and after that

$openssl rsa -in privkey.pem –pubout –out pubkey.pem

I tried with | (pipe) but no.

  • 3
    Why not use &&? – Aurelia Nov 18 '13 at 19:58
1

OK, since noone is trying to answer this I have few tips. OpenSSL doesn't seem to know that.

  1. If you need to use pipe with the private key in stdin, you can use following. E.g. to output the pubkey right away (in fact, it is useless since you don't save the privkey):

    openssl genrsa 2048 | ....

    openssl genrsa 2048 | openssl rsa -pubout

  2. You can use ssh-keygen for similar thing. The following will print the pub/priv rsa key pair with empty passphrase, but afaik it's in a bit different format than the OpenSSL would give you.

    ssh-keygen -t rsa -f file -P ""

  3. And then there is the fact that using && or two separate commands should be okay for most situations.

0

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX

see the accepted answer to this stackoverflow question

  • That produces a privatekey and a selfsigned cert, which is sometimes useful but not what was asked. For what was asked on Unixoid systems openssl genrsa ... | tee private.pem | openssl rsa -pubout >public.pem. Or in 1.0.0+ you can use genpkey and pkey instead, but for RSA there's no benefit. – dave_thompson_085 Jul 5 '14 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.