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:





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. – Maarten Bodewes Jan 11 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 Jan 11 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. – Maarten Bodewes Jan 11 at 16:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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