The following command generates a file which contains both public and private key:
openssl genrsa -des3 -out privkey.pem 2048
Source: here
With OpenSSL, the private key contains the public key information as well, so a public key doesn't need to be generated separately
How can we extract the public key from the privkey.pem file?
Thanks.
openssl rsa -in privkey.pem -pubout > key.pub
That writes the public key to key.pub