compare_keys.sh
#!/bin/bash
 
## Little script to see if a public key and private key
## match one another. Assumes keys are in ~/.ssh/ directory
## and that the pubkey is <privkey_name>.pub
 
# usage:  ./compare_keys privkey_name
 
 
if [ "$#" -ne 1 ]; then
    echo "Invalid arguments"
    exit
fi
 
PRIVKEY=$1
PUBKEY="$PRIVKEY.pub"
OUTPUT=`diff -q <(ssh-keygen -y -e -f ~/.ssh/$PRIVKEY) <( ssh-keygen -y -e -f ~/.ssh/$PUBKEY )`
if [ -z "$OUTPUT" ]; then
    echo "Match"
else
    echo "No Match!!"
fi