tech4 min read

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 ~/.ssh

Look for files like:

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_ed25519

This 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_geekdas

Important 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_geekdas

Step 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_ed25519

This loads your SSH key into memory.

Add SSH Key to GitHub

Step 1: Copy Public Key

cat ~/.ssh/id_ed25519.pub

Copy the entire output.

Step 2: Add to GitHub

  1. Go to GitHub

  2. Click Profile -> Settings

  3. Click SSH and GPG Keys

  4. Click New SSH Key

  5. Paste your public key

  6. Save

Now GitHub recognizes your Linux machine.

Test GitHub SSH Connection

ssh -T git@github.com

If 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.git

then:

git clone git@github.com:username/repository.git

That’s it! No password required.

Practical Examples: Clone Your Own Repository

git clone git@github.com:geekdas/my-project.git

Use Multiple SSH Keys

If you manage multiple GitHub accounts, edit:

nano ~/.ssh/config

add:

Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work

Then clone like:

git clone git@github-work:company/project.git

Common Mistakes and Fixes:

1. Permission Denied (publickey)

Cause:

  • SSH key not added to GitHub

  • SSH agent not running

Fix:

ssh-add ~/.ssh/id_ed25519

2. Cloning Using HTTPS Instead of SSH

Wrong:

https://github.com/user/repo.git

Correct:

git@github.com:user/repo.git

3. Wrong File Permissions

Fix:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

4. SSH Key Not Loaded After Reboot

Add to your .bashrc or .zshrc:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Benefits 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:

  1. Generate SSH key

  2. Add it to SSH agent

  3. Upload public key to GitHub

  4. Test connection

  5. 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.

Frequently Asked Questions

How do I add GitHub SSH key in Linux?
Generate a key using ssh-keygen, add it to SSH agent, copy the public key, and paste it into GitHub -> Settings -> SSH Keys.
How do I clone a Git repository using SSH?
Copy the SSH URL from GitHub and run: git clone git@github.com:username/repo.git
Why is SSH better than HTTPS for GitHub?
SSH avoids password prompts, is more secure, and works better for automation and CI/CD.
Where is SSH key stored in Linux?
SSH keys are stored in: ~/.ssh/ Private key: id_ed25519 Public key: id_ed25519.pub
Can I use multiple SSH keys for GitHub?
Yes, configure multiple keys using the '~/.ssh/config' file and assign different Host aliases.
How do I test if my SSH key works with GitHub?
"ssh -T git@github.com" If successful, GitHub will confirm authentication.

Related Articles