108

Using OpenSSL from the command line in Linux, is there some way to examine a key (either public or private) to determine the key size?

jdw
  • 3,955

2 Answers2

137
openssl rsa -in private.key -text -noout

The top line of the output will display the key size.

For example:

Private-Key: (2048 bit)

To view the key size from a certificate:

openssl x509 -in public.pem -text -noout | grep "Public Key"
RSA Public Key: (2048 bit)
Paul
  • 3,278
Shane Madden
  • 116,404
  • 13
  • 187
  • 256
25

The first (2048) is the bit length of the key:

 $ ssh-keygen -lf /etc/ssh/rsa_key.pub 
 2048 91:1c:ae:17:16:...
Adrien P.
  • 857