Search code examples
amazon-ec2ssh-keys

Which key is in use when ssh logging into my EC2 instance?


After a ssh-keyscan I opened my generated known_hosts file, and found that there are 3 instead of 1 key for my EC2 instance.

**.**.**.** ssh-rsa ******
**.**.**.** ecdsa-sha2-nistp256 ***
**.**.**.** ssh-ed25519 ***

Are they all being used when logging in? Can I safely delete from them if some are not used at all?


Solution

  • If you run ssh-keygen -H -F <your EC2 URI>, it'll tell you which line(s) is/are being used.

    E.g. # Host <whatever>.amazonaws.com found: line 15

    If it's not used, you can delete it. Even if you delete one that's used, it'll just ask you to confirm that it's okay next time you connect.