How to Add GitHub SSH in Linux and Git Clone Using That SSH
Before we dive into setting up SSH for GitHub, make sure you’ve covered the basics. If you’re just getting started, check out the complete guide on how to install Git on Linux, where I explain step-by-step installation. You can also read a detailed article on Git stash commands, which covers how to temporarily save changes without committing them. And if you want a solid foundation, don’t miss the post on important Git commands every developer should know, it’s perfect for beginners and intermediate developers who want to strengthen their Git workflow. Once you’re comfortable with these, setting up GitHub SSH will be much easier and more practical.
If you're a developer using Linux, setting up SSH for GitHub is one of the most important steps for secure and password-free repository access.
Instead of entering your GitHub username and password every time you push or clone a repository, SSH allows secure authentication using cryptographic keys.
In this complete guide, you’ll learn:
How to add GitHub SSH in Linux
How to generate SSH keys
How to add SSH keys to GitHub
How to clone repositories using SSH
Common mistakes and how to fix them
This guide works for Ubuntu, Debian, Fedora, Arch, and most Linux distributions.
Why Use SSH with GitHub?
Using SSH to connect with GitHub provides:
Secure authentication
No repeated password typing
Easy repository access
Ideal for automation and CI/CD
When you configure SSH correctly, you can clone, push, and pull without entering credentials every time.
What is SSH?
SSH (Secure Shell) is a cryptographic protocol used to securely connect and authenticate between systems.
In this case:
Your Linux machine generates a key pair.
You upload the public key to GitHub.
GitHub verifies you using the private key stored locally.
There are two parts of SSH keys:
Private Key → Stored securely on your system
Public Key → Uploaded to GitHub
Check for Existing SSH Keys
Before generating a new key, check if you already have one:
ls -al ~/.sshLook for files like:
id_rsa
id_rsa.pub
id_ed25519
id_ed25519.pub
If they exist, you can reuse them. If not, generate a new one.
Generate a New SSH Key in Linux
Step 1: Generate SSH Key
Use the modern and recommended ED25519 algorithm:
ssh-keygen -t ed25519 -C "your_email@example.com"If ED25519 is not supported, use:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Step 2: Choose File Location
Press Enter to save in the default location:
After running:
ssh-keygen -t ed25519 -C "your_email@example.com"
You’ll see:
Enter file in which to save the key (/home/yourusername/.ssh/id_ed25519):Option 1: Use Default Location (Recommended)
Press Enter to save it in the default location:
/home/yourusername/.ssh/id_ed25519This is the standard and recommended location for most users.
Option 2: Use a Custom Path and File Name
You can also specify a custom path and file name, for example:
/home/yourusername/.ssh/work_geekdasImportant Notes:
The folder must already exist (e.g., ~/.ssh/)
Avoid creating nested folders like ~/.ssh/work/geekdas unless the work/ directory exists
If you use a custom filename, you must specify it later when adding to the SSH agent:
ssh-add ~/.ssh/work_geekdasStep 3: Set Passphrase (Optional)
You can:
Set a passphrase (more secure)
Leave empty for convenience
Your SSH key is now generated.
Add SSH Key to SSH Agent
Start the SSH agent:
eval "$(ssh-agent -s)"Add your private key:
ssh-add ~/.ssh/id_ed25519This loads your SSH key into memory.
Add SSH Key to GitHub
Step 1: Copy Public Key
cat ~/.ssh/id_ed25519.pubCopy the entire output.
Step 2: Add to GitHub
Go to GitHub
Click Profile -> Settings
Click SSH and GPG Keys
Click New SSH Key
Paste your public key
Save
Now GitHub recognizes your Linux machine.
Test GitHub SSH Connection
ssh -T git@github.comIf successful, you’ll see:
Hi username! You've successfully authenticated.If you see:
Permission denied (publickey)Check your SSH key configuration.
Git Clone Using SSH
Now you're ready to clone repositories.
Step 1: Get SSH URL
Go to your repository on GitHub.
Click Code -> Select SSH.
The URL looks like:
git@github.com:username/repository.gitthen:
git clone git@github.com:username/repository.gitThat’s it! No password required.
Practical Examples: Clone Your Own Repository
git clone git@github.com:geekdas/my-project.gitUse Multiple SSH Keys
If you manage multiple GitHub accounts, edit:
nano ~/.ssh/configadd:
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_workThen clone like:
git clone git@github-work:company/project.gitCommon Mistakes and Fixes:
1. Permission Denied (publickey)
Cause:
SSH key not added to GitHub
SSH agent not running
Fix:
ssh-add ~/.ssh/id_ed255192. Cloning Using HTTPS Instead of SSH
Wrong:
https://github.com/user/repo.gitCorrect:
git@github.com:user/repo.git3. Wrong File Permissions
Fix:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed255194. SSH Key Not Loaded After Reboot
Add to your .bashrc or .zshrc:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Benefits of Using SSH for GitHub
1. Enhanced Security
SSH uses public-key cryptography, making it more secure than password authentication.
2. No Repeated Authentication
No need to enter credentials every time.
3. Automation Friendly
Perfect for:
CI/CD pipelines
VPS deployments
Automated scripts
4. Works Seamlessly with Git
SSH integrates smoothly with Git workflows.
Conclusion
Setting up GitHub SSH in Linux is a one time process that saves you time and improves security.
Quick summary:
Generate SSH key
Add it to SSH agent
Upload public key to GitHub
Test connection
Clone using SSH
Once configured, your Git workflow becomes faster, more secure, and more professional.
If you work regularly with GitHub, SSH setup is absolutely essential.