Calculate RSA key fingerprint

后端 未结 14 1467
别那么骄傲
别那么骄傲 2020-11-28 16:55

I need to do the SSH key audit for GitHub, but I am not sure how do find my RSA key fingerprint. I originally followed a guide to generate an SSH key on Linux.

What

相关标签:
14条回答
  • 2020-11-28 17:36

    A key pair (the private and public keys) will have the same fingerprint; so in the case you can't remember which private key belong to which public key, find the match by comparing their fingerprints.

    The most voted answer by Marvin Vinto provides the fingerprint of a public SSH key file. The fingerprint of the corresponding private SSH key can also be queried, but it requires a longer series of step, as shown below.

    1. Load the SSH agent, if you haven't done so. The easiest way is to invoke

      $ ssh-agent bash
      

      or

      $ ssh-agent tcsh
      

      (or another shell you use).

    2. Load the private key you want to test:

      $ ssh-add /path/to/your-ssh-private-key
      

      You will be asked to enter the passphrase if the key is password-protected.

    3. Now, as others have said, type

      $ ssh-add -l
      1024 fd:bc:8a:81:58:8f:2c:78:86:a2:cf:02:40:7d:9d:3c you@yourhost (DSA)
      

      fd:bc:... is the fingerprint you are after. If there are multiple keys, multiple lines will be printed, and the last line contains the fingerprint of the last loaded key.

    4. If you want to stop the agent (i.e., if you invoked step 1 above), then simply type `exit' on the shell, and you'll be back on the shell prior to the loading of ssh agent.

    I do not add new information, but hopefully this answer is clear to users of all levels.

    0 讨论(0)
  • 2020-11-28 17:37
    $ ssh-add -l 
    

    will also work on Mac OS X v10.8 (Mountain Lion) - v10.10 (Yosemite).

    It also supports the option -E to specify the fingerprint format so in case MD5 is needed (it's often used, e.g. by GitHub), just add -E md5 to the command.

    0 讨论(0)
  • 2020-11-28 17:38

    Run the following command to retrieve the SHA256 fingerprint of your SSH key (-l means "list" instead of create a new key, -f means "filename"):

    $ ssh-keygen -lf /path/to/ssh/key
    

    So for example, on my machine the command I ran was (using RSA public key):

    $ ssh-keygen -lf ~/.ssh/id_rsa.pub
    2048 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff /Users/username/.ssh/id_rsa.pub (RSA)
    

    To get the GitHub (MD5) fingerprint format with newer versions of ssh-keygen, run:

    $ ssh-keygen -E md5 -lf <fileName>
    

    Bonus information:

    ssh-keygen -lf also works on known_hosts and authorized_keys files.

    To find most public keys on Linux/Unix/OS X systems, run

    $ find /etc/ssh /home/*/.ssh /Users/*/.ssh -name '*.pub' -o -name 'authorized_keys' -o -name 'known_hosts'
    

    (If you want to see inside other users' homedirs, you'll have to be root or sudo.)

    The ssh-add -l is very similar, but lists the fingerprints of keys added to your agent. (OS X users take note that magic passwordless SSH via Keychain is not the same as using ssh-agent.)

    0 讨论(0)
  • 2020-11-28 17:40

    To check a remote SSH server prior to the first connection, you can give a look at www.server-stats.net/ssh/ to see all SHH keys for the server, as well as from when the key is known.

    That's not like an SSL certificate, but definitely a must-do before connecting to any SSH server for the first time.

    0 讨论(0)
  • 2020-11-28 17:45

    If your SSH agent is running, it is

    ssh-add -l
    

    to list RSA fingerprints of all identities, or -L for listing public keys.

    If your agent is not running, try:

    ssh-agent sh -c 'ssh-add; ssh-add -l'
    

    And for your public keys:

    ssh-agent sh -c 'ssh-add; ssh-add -L'
    

    If you get the message: 'The agent has no identities.', then you have to generate your RSA key by ssh-keygen first.

    0 讨论(0)
  • 2020-11-28 17:48

    The fastest way if your keys are in an SSH agent:

    $ ssh-add -L | ssh-keygen -E md5 -lf /dev/stdin
    

    Each key in the agent will be printed as:

    4096 MD5:8f:c9:dc:40:ec:9e:dc:65:74:f7:20:c1:29:d1:e8:5a /Users/cmcginty/.ssh/id_rsa (RSA)
    
    0 讨论(0)
提交回复
热议问题