Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use RSA private key to generate public key?

I don't really understand this one:

According to https://www.madboa.com/geek/openssl/#key-rsa, you can generate a public key from a private key.

openssl genrsa -out mykey.pem 1024 openssl rsa -in mykey.pem -pubout > mykey.pub 

My initial thinking was that they are generated in a pair together.

Does the RSA private key contain the sum? Or the public key?

like image 328
c2h2 Avatar asked Mar 09 '11 10:03

c2h2


People also ask

Can you derive RSA public key from private key?

It is theoretically possible but for large keys computationally infeasible.

Can you generate a new public key from a private key?

To generate the missing public key again from the private key, the following command will generate the public key of the private key provided with the -f option. $ ssh-keygen -y -f ~/.

Does RSA private key include public key?

RSA private and public keys. An RSA key pair includes a private and a public key. The RSA private key is used to generate digital signatures, and the RSA public key is used to verify digital signatures. The RSA public key is also used for key encryption of DES or AES DATA keys and the RSA private key for key recovery.


2 Answers

openssl genrsa -out mykey.pem 1024 

will actually produce a public - private key pair. The pair is stored in the generated mykey.pem file.

openssl rsa -in mykey.pem -pubout > mykey.pub 

will extract the public key and print that out. Here is a link to a page that describes this better.

EDIT: Check the examples section here. To just output the public part of a private key:

openssl rsa -in key.pem -pubout -out pubkey.pem 

To get a usable public key for SSH purposes, use ssh-keygen:

ssh-keygen -y -f key.pem > key.pub 
like image 80
Raam Avatar answered Oct 13 '22 11:10

Raam


People looking for SSH public key...

If you're looking to extract the public key for use with OpenSSH, you will need to get the public key a bit differently

$ ssh-keygen -y -f mykey.pem > mykey.pub 

This public key format is compatible with OpenSSH. Append the public key to remote:~/.ssh/authorized_keys and you'll be good to go


docs from SSH-KEYGEN(1)

ssh-keygen -y [-f input_keyfile]   

-y This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.

like image 25
Mulan Avatar answered Oct 13 '22 11:10

Mulan