← Back to Chapters

GitHub Add SSH

? GitHub Add SSH

? Quick Overview

This section explains how to add an SSH key to GitHub so you can securely interact with repositories without entering your username and password every time.

? Key Concepts

  • SSH provides encrypted authentication
  • Public key is shared with GitHub
  • Private key stays on your system

? Syntax / Theory

SSH (Secure Shell) allows GitHub to identify you using cryptographic keys instead of passwords, making Git operations faster and more secure.

? Step 1: Generate an SSH Key

? View Code Example
# Generate a new SSH key using RSA algorithm
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

? Step 2: Copy SSH Public Key

? View Code Example
# Display the public SSH key
cat ~/.ssh/id_rsa.pub

? Step 3: Add SSH Key to GitHub

  1. Open GitHub → Settings → SSH and GPG keys
  2. Click New SSH key
  3. Paste your copied key
  4. Save

✅ Step 4: Test SSH Connection

? View Code Example
# Test SSH authentication with GitHub
ssh -T git@github.com
? View Output
# Successful authentication message
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

? Using SSH with Git

? Clone Repository
# Clone repository using SSH URL
git clone git@github.com:username/repository.git
? Push Changes
# Push commits to GitHub
git push origin main
? Pull Changes
# Pull latest changes from GitHub
git pull origin main

? Use Cases

  • Secure GitHub authentication
  • Password-free Git operations
  • CI/CD and automation

? Tips & Best Practices

  • Protect private keys
  • Use passphrases
  • Remove unused keys

? Try It Yourself

  • Generate and add a new SSH key
  • Test SSH connection
  • Clone and push to a repository