Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
There are many different ways depending on the format of the keypair. Were you looking at a specific format? – Zoredache Oct 27 '11 at 19:55
up vote 55 down vote accepted
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 "RSA Public Key"
RSA Public Key: (2048 bit)
share|improve this answer
And if he is using DSA, or something else. How about determining the key size from the public key(cert). – Zoredache Oct 27 '11 at 19:51
@Zoredache Yeah - I could have sworn the question said "private key" specifically; either I'm losing it or an edit beat the 5 minute timer. – Shane Madden Oct 27 '11 at 20:13
OpenSSL 1.0.1g 7 Apr 2014 format requires | grep "Public-Key" – Vadzim Sep 15 '15 at 7:23

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

 $ ssh-keygen -lf /etc/ssh/ 
 2048 91:1c:ae:17:16:...
share|improve this answer
He said 'openssl', not 'openssh'. – MikeyB Oct 27 '11 at 20:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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