Skip to content

Instantly share code, notes, and snippets.

@initialed85
Last active July 8, 2019 04:04
Show Gist options
  • Save initialed85/bd7fff524a6c42efa35de33218075487 to your computer and use it in GitHub Desktop.
Save initialed85/bd7fff524a6c42efa35de33218075487 to your computer and use it in GitHub Desktop.
Create a public key for an AWS private key
#!/bin/bash
# props to original at https://gist.github.com/zircote/1243501
if [[ "${1}" == "" ]]; then
echo "usage: ${0} some_private_key.pem"
echo ""
echo "The result will be a public key at $(pwd)/some_private_key.pub"
exit 1
fi
PRIVATE=${1}
BASE=$(basename -s .pem ${PRIVATE})
PUBLIC=${BASE}.pub
if [[ -e ${PUBLIC} ]]; then
echo "error: public key ${PUBLIC} already exists"
exit 1
fi
ssh-keygen -y -f ${PRIVATE} > ${PUBLIC}
if [[ ${?} -ne 0 ]]; then
rm -fr ${PUBLIC}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment