Complete and safe guide to create an SSH key, add it to GitHub
Here's a complete and safe guide to create an SSH key, add it to GitHub, and start using it to push/pull code securely:
✅ STEP 1: Generate a New SSH Key
On your local machine, run:
ssh-keygen -t ed25519 -C "your_email@example.com"
Replace
"your_email@example.com"
with your GitHub email.
You’ll see:
Enter file in which to save the key (/home/your-user/.ssh/id_ed25519):
Just press Enter
to accept the default path.
Then:
Enter passphrase (optional):
- You can press
Enter
for no passphrase - Or enter one for extra security
✅ This creates:
- Private key:
~/.ssh/id_ed25519
- Public key:
~/.ssh/id_ed25519.pub
✅ STEP 2: Add SSH Key to SSH Agent
Run:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
This loads your SSH key into the agent so Git can use it.
✅ STEP 3: Add SSH Key to GitHub
-
Show your public key:
cat ~/.ssh/id_ed25519.pub
-
Copy the entire output (starts with
ssh-ed25519
…) -
Click "New SSH key"
- Title: Any label (e.g., "My Laptop")
- Key: Paste the public key you copied
-
Click "Add SSH key"
✅ STEP 4: Test the SSH Connection
ssh -T git@github.com
You should see:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
✅ STEP 5: Use SSH for Your Repos
When cloning a repo, use this:
git clone git@github.com:your-username/your-repo.git
Or change your remote URL in an existing repo:
git remote set-url origin git@github.com:your-username/your-repo.git
🛠 Bonus Tip: Configure Git Identity (if not done)
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"