How do you test a public/private DSA keypair?

后端 未结 11 1182
日久生厌
日久生厌 2020-12-12 08:35

Is there an easy way to verify that a given private key matches a given public key? I have a few *.puband a few *.key files, and I need to check w

11条回答
  •  失恋的感觉
    2020-12-12 09:29

    Enter the following command to check if a private key and public key are a matched set (identical) or not a matched set (differ) in $USER/.ssh directory. The cut command prevents the comment at the end of the line in the public key from being compared, allowing only the key to be compared.

    ssh-keygen -y -f ~/.ssh/id_rsa | diff -s - <(cut -d ' ' -f 1,2 ~/.ssh/id_rsa.pub)
    

    Output will look like either one of these lines.

    Files - and /dev/fd/63 are identical
    
    Files - and /dev/fd/63 differ
    

    I wrote a shell script that users use to check file permission of their ~/.ssh/files and matched key set. It solves my challenges with user incidents setting up ssh. It may help you. https://github.com/BradleyA/docker-security-infrastructure/tree/master/ssh

    Note: My previous answer (in Mar 2018) no longer works with the latest releases of openssh. Previous answer: diff -qs <(ssh-keygen -yf ~/.ssh/id_rsa) <(cut -d ' ' -f 1,2 ~/.ssh/id_rsa.pub)

提交回复
热议问题