Created
September 17, 2025 12:37
-
-
Save kaspermunch/e8f5a3b5ba93bec991b4a256797bd039 to your computer and use it in GitHub Desktop.
Set up ssh keys on GitHub
This file contains hidden or 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
| 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