Created
October 25, 2023 14:44
-
-
Save leonardobazico/ddbff8b2ac1edca052e69058946b518a to your computer and use it in GitHub Desktop.
Generate ssh key if doesn't exists and copy it
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/sh | |
KEY_PATH="$HOME/.ssh/id_rsa"; \ | |
PRINT_PUBLIC_KEY="cat $KEY_PATH.pub "; \ | |
GENERATE_KEY="ssh-keygen -t rsa -N '' -f $KEY_PATH"; \ | |
COPY_KEY="$PRINT_PUBLIC_KEY | pbcopy"; \ | |
{ sh -c $PRINT_PUBLIC_KEY || \ | |
{ echo "Generating ssh key" && sh -c $GENERATE_KEY; }; } && \ | |
sh -c $COPY_KEY && echo "Copied ssh key to clipboard" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment