Created
July 28, 2021 13:49
-
-
Save rafaelcpalmeida/3f7c85a01bffa12e6ab4ee19d14fba3c to your computer and use it in GitHub Desktop.
Generate public-private key pair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
NAME=${1:-} | |
mkdir -p "$HOME/.keys-pairs/$NAME" | |
cd "$HOME/.keys-pairs/$NAME" | |
PRIVATE_PEM="private.pem" | |
PUBLIC_PEM="public.pem" | |
PUBLIC_TXT="public_key.txt" | |
ssh-keygen -t rsa -b 2048 -m PEM -f "$PRIVATE_PEM" -q -N "" | |
openssl rsa -in "$PRIVATE_PEM" -pubout -outform PEM -out "$PUBLIC_PEM" 2>/dev/null | |
openssl rsa -in "$PRIVATE_PEM" -pubout -outform DER | base64 > "$PUBLIC_TXT" | |
rm "$PRIVATE_PEM".pub | |
echo "Public key to saved in $PWD/$PUBLIC_TXT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment