I have two files, id_rsa
and id_rsa.pub
. What command can be used to validate if they are a valid pair?
How to Check if an RSA Public/Private Key Pair Match – Linux Security SSH RSA Command
commandlinuxrsaSecurityssh
Related Topic
- Git for Windows – How to Tell Git Where to Find Private RSA Key
- Security – How to Deal with a Compromised Server
- Security – Our security auditor is an idiot. How to give him the information he wants
- Ssh – How to validate an RSA SSH public key file (id_rsa.pub)
- SSH – Private and Public Key in Same Directory Causes Failure
- Ssh – Putting RSA keys into azure key vault
- Ssh – Why is the same private key file generating two different public key strings
Best Answer
I would prefer the
ssh-keygen -y -e -f <private key>
way instead of the accepted answer of How do you test a public/private DSA keypair? on Stack Overflow.ssh-keygen -y -e -f <private key>
takes a private key and prints the corresponding public key which can be directly compared to your available public keys. (Hint: beware of comments or key-options.)(How the hell is it doing that? I can only hope the public key is encoded directly or indirectly in the private key...)
I needed this myself and used the following Bash one-liner. It should output nothing if the keys belong together. Apply a little
-q
to the diff in scripts and diff only sets the return code appropriately.