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.
For those interested in the details - you can see what's inside the public key file (generated as explained above), by doing this:-
or for the private key file, this:-
which outputs as text on the console the actual components of the key (modulus, exponents, primes, ...)
Though, the above technique works for the general case, it didn't work on Amazon Web Services (AWS) PEM files.
I did find in the AWS docs the following command works:
ssh-keygen -y
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
edit Thanks @makenova for the complete line:
If your looking how to copy an Amazon AWS
.pem
keypair into a different region do the following:Then
For AWS importing an existing public key,
Export from the .pem doing this... (on linux)
This will produce a file which if you open in a text editor looking something like this...
However AWS will NOT accept this file.
You have to strip off the
-----BEGIN PUBLIC KEY-----
and-----END PUBLIC KEY-----
from the file. Save it and import and it should work in AWS.That writes the public key to
key.pub