Generate SSH Key for GitHub
SSH keys provide a secure way to authenticate with GitHub without entering your password each time.
Step 1: Generate SSH key
Generate a new SSH key pair using the Ed25519 algorithm:
bash
ssh-keygen -t ed25519 -C "your_email@example.com"
When prompted:
- Press Enter to accept the default file location
- Enter a secure passphrase (recommended) or press Enter for no passphrase
Step 2: Start ssh-agent
Start the SSH agent in the background:
bash
eval "$(ssh-agent -s)"
This command starts the SSH agent and adds it to your current session.
Step 3: Add SSH private key to agent
Add your private key to the SSH agent:
bash
ssh-add ~/.ssh/id_ed25519
If you set a passphrase, you'll be prompted to enter it.
Step 4: Copy public key to clipboard
Copy your public key to the clipboard for easy pasting:
bash
xclip -sel clip < ~/.ssh/id_ed25519.pub
If xclip
is not installed, you can install it with sudo apt install xclip
.
Step 5: Add key to GitHub
- Go to GitHub.com and sign in
- Click your profile picture → Settings
- Click "SSH and GPG keys" in the sidebar
- Click "New SSH key"
- Give it a descriptive title
- Paste your public key in the "Key" field
- Click "Add SSH key"
Step 6: Test the connection
Test your SSH connection to GitHub:
bash
ssh -T git@github.com
You should see a message like "Hi username! You've successfully authenticated..."
Next Steps
Now you can:
- Clone repositories using SSH URLs
- Push and pull without entering passwords
- Use SSH for secure Git operations