Skip to content

Instantly share code, notes, and snippets.

@niclaslindstedt
Last active September 25, 2021 11:51
Show Gist options
  • Save niclaslindstedt/cc22b56774475f4345dc9c6f129136a0 to your computer and use it in GitHub Desktop.
Save niclaslindstedt/cc22b56774475f4345dc9c6f129136a0 to your computer and use it in GitHub Desktop.
Generate SSH Key
#!/bin/bash
# Run this remotely:
# curl -fsSL https://gist.githubusercontent.com/niclaslindstedt/cc22b56774475f4345dc9c6f129136a0/raw/7f19198ca1970f9168ea29cb9cb4035793b5a09b/generate_ssh_key.sh | bash -
main() {
local gh_email ssh_key_path answer
ssh_key_path="$HOME/.ssh/id_ed25519"
[ ! -f "$ssh_key_path" ] && {
echo;echo "*** Setting up SSH key ***"
echo -n "Enter your GitHub e-mail: "
read -r gh_email
ssh-keygen -t ed25519 -a 100 -C "$gh_email" -f "$ssh_key_path" -N "" &>/dev/null || {
echo "Could not generate SSH key"
exit 1
}
}
echo "Copy the key below to a new SSH key on GitHub -> https://github.com/settings/keys"
echo
cat "${ssh_key_path}.pub"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment