Tired of generating personal access tokens every time you want to clone a private repository? If you’ve been battling “403 Forbidden” errors, switching to SSH is the best move you can make. You only have to set it up once per machine, and it securely handles your authentication in the background.
Here is exactly how to get it running.
Phase 1: Generate and Store Your Key
First, we need to create a secure key pair on your machine. Open your terminal (or Git Bash on Windows) and paste this command, replacing the placeholder with your GitHub email address:
Bash
ssh-keygen -t ed25519 -C "your_email@example.com"
Press Enter to accept the default file location. When prompted for a passphrase, you can type one for extra security or press Enter twice to skip it.
Next, fire up your SSH agent in the background and add your newly minted key to it:
Bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Phase 2: Add the Key to Your GitHub Account
Now, you need to hand the “public” half of your key over to GitHub. Print the key to your terminal screen:
Bash
cat ~/.ssh/id_ed25519.pub
Copy the entire output (it usually starts with ssh-ed25519 and ends with your email). Then, hop over to your browser:
- Navigate to your GitHub Settings.
- Click on SSH and GPG keys in the left sidebar.
- Hit the green New SSH key button.
- Give it a memorable title (e.g., “Personal Laptop”) and paste your copied key into the large text box.
- Click Add SSH key.
Phase 3: Test the Connection and Clone
Let’s make sure your machine and GitHub are talking to each other correctly. Run this quick test in your terminal:
Bash
ssh -T git@github.com
Quick Tip: If a warning pops up asking if you want to continue connecting to the host, simply type yes and hit Enter.
If you see a message saying, “Hi username! You’ve successfully authenticated,” you are good to go! You can now bypass the HTTPS errors entirely and clone your repository using the SSH URL format:
Bash
git clone git@github.com:th127/zthd.git
Discover more from Science Safari
Subscribe to get the latest posts sent to your email.