Skip to content

Instantly share code, notes, and snippets.

@kaspermunch
Created September 17, 2025 12:37
Show Gist options
  • Select an option

  • Save kaspermunch/e8f5a3b5ba93bec991b4a256797bd039 to your computer and use it in GitHub Desktop.

Select an option

Save kaspermunch/e8f5a3b5ba93bec991b4a256797bd039 to your computer and use it in GitHub Desktop.
Set up ssh keys on GitHub
echo ""
echo "Log into GitHub through the browser using a one-time code"
gh auth login --hostname github.com -p ssh --skip-ssh-key --web --scopes "admin:public_key,repo,read:org"
filename="$HOME/.ssh/id_ed25519"
echo "Generatig SSH key"
if [[ ! -f "$filename" ]]; then
ssh-keygen -t ed25519 -f "$filename" -N ""
fi
echo "Starting ssh-agent"
eval "$(ssh-agent -s)"
echo "Adding key"
ssh-add "$filename"
echo "Adding key to GitHub using gh CLI"
gh ssh-key add "$filename.pub" --title "My SSH key"
echo "Testing the ssh connection"
if ssh -T [email protected] 2>&1 | grep -q "successfully authenticated"; then
echo "Success! GitHub SSH is working"
else
echo "Setting up GitHub SSH failed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment