On my server ~/.ssh/authorized_keys contains only 1 public key. However, I can connect to it using 2 different private keys.

One private key looks like this:



The other private key looks like this:




1 Answer 1


This could well be the same key in two different formats. Try extracting the public key for both and compare the fingerprints, for instance using the commands here. The public key is unique and part of the public key / private key pair. The fingerprint over the public key is unique with very high probability. So if the comparison succeeds you've got the same private key.

The fingerprint comparison should be sufficient, but to be even more sure you could generate a signature using the private key and verify it using the public key generated from the other private key. If it verifies the public and private keys are part of a key pair. SSH is however not meant for this kind of operation so it will be harder to accomplish - and it is only slightly more solid than creating a secure connection in the first place.

  • Manual comparison, possibly after conversion of one key type to another could also work but is very error prone and requires knowledge - conversion + binary compare is not recommended, as there are indeed multiple ways to store the same key. Commented Jan 11, 2019 at 12:38
  • The fingerprint comparison method is kind of a tautology. The question is why 2 private keys correspond to the same public key and fingerprint comparison verifies that they have the same public key. Is it possible to convert a private key to the format of the other one then compare them?
    – an0
    Commented Jan 11, 2019 at 16:40
  • One public key can only correspond to one particular private key otherwise you could decrypt or generate signatures as if you possess the other key. The fingerprint check is more to confirm that there aren't multiple key pairs at play. Yes you can also compare private keys but note that the encoding of private keys may differ even if they are the same mathematically speaking. Commented Jan 11, 2019 at 16:46
  • 1
    Specifically, these are the two formats used by OpenSSH for privatekey files (other than obsolete v1-rsa keys, which ssh-keygen formerly called type 'rsa1'). Until 6.5 in 2014, OpenSSH used the OpenSSL-defined 'traditional' (meaning not PKCS8) PEM format. As an option since then, and default since 7.8 last year, OpenSSH uses its own privatekey format, hence the PEM type 'OPENSSH PRIVATE KEY'. Yes it is actually the same key inside, just a different storage format (XDR-based instead of ASN.1). To convert between them see the ssh-keygen man page under -m (unless ancient). Commented Aug 3, 2019 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .