
Introduction: SSH vs HTTPS for GitHub Authentication
When working with remote repositories, there are two primary ways developers authenticate their local machines with remote repositories:
HTTPS Authentication
SSH (Secure Shell) Authentication
NOTE: In this article we will see the steps for GitHub, but for other service providers the steps will be similar.
1. HTTPS Login
With HTTPS, every time you interact with a remote repository (like git push, git pull, or git clone), GitHub asks for your username and personal access token (PAT)/Password.
Requires credential caching or a credential manager to avoid typing every time
Simple to set up
Can be cumbersome if working with multiple accounts.
Learn how to setup multiple git/github account for SSH
2. SSH Authentication
SSH uses a public-private key pair for secure, password-less authentication between your machine and GitHub. Once you add your public SSH key to your GitHub account, your computer can securely authenticate with GitHub without needing to enter your username and password or PAT.
No need to enter credentials for every operation
More secure, encrypted connection
Easily manage multiple accounts using SSH config Link
Perfect for frequent collaborators or CI/CD setups
Why Choose SSH?
Secure, encrypted connection
No repeated password/token prompts
Clean handling of multiple GitHub accounts
Works well for automation, CI/CD, and team setups
Let's see the steps to configure the SSH Authentication.
Step 1: Check for Existing SSH Keys
See if you already have any SSH keys:
ls -al ~/.ssh
If you see files like id_ed25519 and id_ed25519.pub, you might already have one & If you don't want to generate a new key then skip Step 2 & proceed to the next step.
If there is no file/key present or you want to generate a new keys then follow the next steps.
Step 2: Generate a New SSH Key
Use this command to create a new Ed25519 SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"
NOTE: This will replace the existing key if any and it will affect the auth if configured any.
After running this command you will see 2 files named id_ed25519 (private key) and id_ed25519.pub (public key) in your .ssh folder.
If you need to keep the existing ones for a different use (another service or project), generate a new key with a custom file name:
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/custom_key_name
After running this command you will see 2 files named custom_key_name (private key) and custom_key_name.pub (public key) in your .ssh folder.
For time being, Let's assume we have id_ed25519 and id_ed25519.pub keys in our .ssh folder
Explanation:
-t ed25519: Specifies the key type (Ed25519 is modern, secure, and fast)-C "your_email@example.com": A comment to label the key (usually your GitHub email)-f ~/.ssh/custom_key_name: Defines the full path and filename of both public and private key being created
When prompted:
Enter file location: press
Enterto accept default (/home/some_name/.ssh/id_ed25519)Enter a passphrase (optional but recommended for extra security)
Step 3: Add the SSH Key to Your SSH Agent
Start the SSH agent:
eval "$(ssh-agent -s)"
Add your new SSH private key to the agent:
ssh-add ~/.ssh/id_ed25519
If you have generated custom key in step 2 then add that key as well,
ssh-add ~/.ssh/custom_key_name
Check if its added:
ssh-add -l
Optional: If you have multiple keys, manage them using an SSH config file (~/.ssh/config):
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/custom_key_name
IdentitiesOnly yes
NOTE: You don't need to add anything in the config file if there is only 1 key pairs.
Step 4: Add the SSH Public Key to GitHub
Copy the public key:
cat ~/.ssh/id_ed25519.pub
Copy the output.
Go to:
GitHub -> Settings
SSH and GPG keys
Click New SSH key
Paste your public key
Give it a Title and Save
Step 5: Test the SSH Connection
Verify your SSH connection to GitHub:
ssh -T git@github.com
If you have multiple keys and have entry in the config file.
ssh -T git@github.com # uses id_ed25519
ssh -T git@bitbucket.org # uses custom_key_name
NOTE: Here github.com and bitbucket.org is a host alias name (and not the keyname) you define in your ~/.ssh/config file.
On success, you should see:
Hi your_username! You've successfully authenticated...
Step 6: Configure Git User Info (Optional but Recommended)
Set your Git global identity:
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
This identity is used for commit history metadata.
If you have multiple keys and have entry in the config file, then you have to setup git per repo identity
In GitHub repo
git config user.name "github user"
git config user.email "githubemail@exmaple.com"
In BitBucket repo
git config user.name "bitbucket user"
git config user.email "bitbucketemail@bitbucket.com"
Step 7: Set SSH Remote URL for Your Repository
If your repo is already cloned using HTTPS (example: https://github.com/username/repo.git), convert it to SSH:
- Check current remote:
git remote -v
- Change it to SSH:
git remote set-url origin git@github.com:username/repository.git
Replace username and repository with your actual GitHub username and repo name.
NOTE: Make sure that, If you have configured the config file then in place of github.com your host alias name will go.
From now on, when you git push or git pull, Git will use your SSH key for authentication.
Lets see some QnA
Q. What if we have only one key pair, in this case do we need any config file ?
A. No we don't need any config file.
Q. Will ssh -T git@github.com , ssh -T git@bitbucket.org uses same key if there is a single key pairs?
A. If You Have Only One Key (id_ed25519)
Let’s say your ~/.ssh/ folder has:
id_ed25519
id_ed25519.pub
And you haven’t set any custom config.
Then:
| Command | What SSH Will Do |
ssh -T git@github.com | Offer the id_ed25519 key for authentication to GitHub |
ssh -T git@bitbucket.org | Offer the same id_ed25519 key for authentication to Bitbucket |
Because — by default — SSH will:
Check the SSH agent for loaded keys
Then look for default keys in:
~/.ssh/id_rsa~/.ssh/id_ecdsa~/.ssh/id_ed25519etc.
If it finds only one key, it offers that key for any connection, whether it’s GitHub, Bitbucket, GitLab, or any other SSH service.
If both services (GitHub and Bitbucket) have this same public key registered in their settings, authentication will work fine.
Recap:
Generate SSH key
Add to SSH agent
Add public key to GitHub
Test SSH connection
Set or update remote URL
Optionally configure Git global username and email
About the author
CapsCode: Empowering Innovation Through Education and Technology
CapsCode is a pioneering edtech and web development company committed to transforming the lives of students and businesses alike. Founded with the vision of creating a brighter, tech-driven future, CapsCode empowers students by providing world-class coding education while enabling businesses to achieve their goals with cutting-edge IT solutions.
For Students At CapsCode, we believe that coding is the language of tomorrow. Through engaging and industry-relevant courses, personalized mentoring, and hands-on workshops, we help students develop: Problem-solving skills: Preparing them for real-world challenges. Technical expertise: Equipping them with practical knowledge of coding and web development. Confidence in technology: Making them future-ready for careers in IT and beyond.
We foster an environment where students not only learn to code but also learn to innovate, collaborate, and think critically.
For Businesses CapsCode offers bespoke IT solutions tailored to the unique needs of businesses. From responsive web development to advanced digital marketing strategies, our services are designed to help companies grow their online presence and streamline their operations. Our key offerings include: Custom website and software development E-commerce platform creation Lead generation and digital marketing Professional email and Google Business setup
We act as partners in innovation, helping businesses leverage technology to reach new heights.
Our Mission Our mission is to empower individuals and organizations by bridging the gap between technology and accessibility. We aim to inspire a new generation of coders while helping businesses thrive in a competitive digital landscape.
Why Choose CapsCode? Over 9 years of IT industry expertise. A blend of education and professional IT services under one roof. A commitment to fostering growth, innovation, and success.
Join us in shaping the future—whether you're a student eager to unlock your potential or a business ready to embrace the possibilities of technology.
Learn. Build. Grow. With CapsCode.
Comments
Join the discussionNo comments yet. Be the first to comment.





