1

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:

-----BEGIN RSA PRIVATE KEY-----
MIIEoQIBAAKCAQEAqaO1eFD6XTTbmcItrptJxRJr89oW2gwlFU0tt8oF/6ZbOfV9

p1RjkISOfKl7YEElZEBHsl/ikCgv2C8DIOTTknXYDXeIxi/PMg==
-----END RSA PRIVATE KEY-----

The other private key looks like this:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jYmMAAAAGYmNyeXB0AAAAGAAAABDwMB0nEv

LlI3s=
-----END OPENSSH PRIVATE KEY-----

Why?

3

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 agree to our terms of service, privacy policy and cookie policy

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