GitHub SSH Setup
Set up SSH keys for secure Git authentication
GitHub SSH Setup
SSH keys let you authenticate with GitHub without entering your password every time you push or pull.
Why SSH?
- No password prompts when pushing/pulling
- More secure than HTTPS with passwords
- Required for automated deployments
Step 1: Check for Existing Keys
First, check if you already have SSH keys:
ls -al ~/.sshIf you see id_ed25519.pub or id_rsa.pub, you already have keys. Skip to Step 4.
Step 2: Generate SSH Key
Open Terminal and run:
ssh-keygen -t ed25519 -C "your_email@example.com"Replace your_email@example.com with your GitHub email.
Follow the prompts:
Enter file in which to save the key (/Users/you/.ssh/id_ed25519): [Press Enter]
Enter passphrase (empty for no passphrase): [Enter passphrase or press Enter]
Enter same passphrase again: [Confirm passphrase]Passphrase: Optional but recommended. Adds extra security if someone accesses your computer.
Open Git Bash or PowerShell and run:
ssh-keygen -t ed25519 -C "your_email@example.com"Follow the prompts to save the key and set a passphrase.
Step 3: Add Key to SSH Agent
Start SSH Agent
eval "$(ssh-agent -s)"Add Key to Agent
ssh-add --apple-use-keychain ~/.ssh/id_ed25519Configure SSH (Optional)
Create ~/.ssh/config for automatic key loading:
nano ~/.ssh/configAdd:
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519Save with Ctrl+O, exit with Ctrl+X.
Start SSH Agent
In PowerShell (Admin):
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agentAdd Key to Agent
ssh-add ~/.ssh/id_ed25519Start SSH Agent
eval "$(ssh-agent -s)"Add Key to Agent
ssh-add ~/.ssh/id_ed25519Step 4: Add Key to GitHub
Copy Your Public Key
pbcopy < ~/.ssh/id_ed25519.pubGet-Content ~/.ssh/id_ed25519.pub | Set-ClipboardOr manually copy:
cat ~/.ssh/id_ed25519.pubcat ~/.ssh/id_ed25519.pubSelect and copy the output.
Open GitHub Settings
- Go to github.com and sign in
- Click your profile photo (top right)
- Click Settings
![]()
Add Your Key
- Title: Enter a name (e.g., "MacBook Pro", "Work Laptop")
- Key type: Keep as "Authentication Key"
- Key: Paste your public key
![]()
- Click Add SSH key
- Confirm with your GitHub password if prompted
Step 5: Test Connection
Verify your SSH setup:
ssh -T git@github.comFirst time connecting? You'll see:
The authenticity of host 'github.com' can't be established.
Are you sure you want to continue connecting (yes/no)?Type yes and press Enter.
Success message:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.This message is normal and means SSH is working correctly.
Using SSH for Git Operations
Clone with SSH
When cloning repositories, use the SSH URL:
# SSH (recommended)
git clone git@github.com:chohra-med/aimobileLauncher_standart.git
# Instead of HTTPS
git clone https://github.com/chohra-med/aimobileLauncher_standart.gitGet SSH URL from GitHub
- Go to the repository on GitHub
- Click the green Code button
- Select SSH tab
- Copy the URL
![]()
Update Existing Repository
If you cloned with HTTPS, switch to SSH:
# Check current remote
git remote -v
# Update to SSH
git remote set-url origin git@github.com:username/repo.git
# Verify change
git remote -vCommon Issues
| Issue | Solution |
|---|---|
| "Permission denied (publickey)" | Ensure key is added to GitHub and SSH agent |
| "Could not open connection to agent" | Run eval "$(ssh-agent -s)" |
| "Bad configuration option: usekeychain" | Remove UseKeychain line (Linux only) |
| Key not working after restart | Add SSH config file (see Step 3) |
Debug SSH Connection
ssh -vT git@github.comThis shows detailed connection info to help troubleshoot.
Quick Reference
# Generate key
ssh-keygen -t ed25519 -C "email@example.com"
# Start agent
eval "$(ssh-agent -s)"
# Add key to agent
ssh-add ~/.ssh/id_ed25519
# Copy public key (macOS)
pbcopy < ~/.ssh/id_ed25519.pub
# Test connection
ssh -T git@github.com
# Clone with SSH
git clone git@github.com:chohra-med/aimobileLauncher_standart.git