Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leonardobazico/ddbff8b2ac1edca052e69058946b518a to your computer and use it in GitHub Desktop.
Save leonardobazico/ddbff8b2ac1edca052e69058946b518a to your computer and use it in GitHub Desktop.
Generate ssh key if doesn't exists and copy it
#!/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