Sitemap
TheRandomguy

TheRandomguy

How to Set Up SSH Authentication for GitHub on Linux

7 min readAug 29, 2026

--

If you work with GitHub from a Linux machine, setting up SSH authentication is one of the first things worth doing.

Once configured, you can clone repositories, pull changes, and push your code to GitHub without entering your GitHub username and password every time.

This guide walks through the complete setup from generating an SSH key to connecting it with GitHub and using it with Git.

Note: This guide focuses on Linux. The overall SSH concept is the same on Windows and macOS, but the commands, file locations, and SSH-agent setup can differ.

What Is SSH and Why Use It With GitHub?

SSH stands for Secure Shell. It provides a secure way for your computer to authenticate with a remote service such as GitHub.

Instead of authenticating with your GitHub password, SSH uses a key pair:

  • Private key — stored on your computer and kept secret.
  • Public key — generated as part of the key pair and added to your GitHub account.

The basic idea is:

Your Linux Machine
│
│ Private Key
│
▼
SSH Authentication
│
▼
GitHub
▲
│
│ Public Key
│
GitHub Account

The private key stays on your computer. GitHub stores the public key.

When your computer connects to GitHub, GitHub verifies that your private key corresponds to the public key registered with your account.

Important security rule

Never share your private key.

Your private key will normally be stored at:

~/.ssh/id_ed25519

Your public key will normally be:

~/.ssh/id_ed25519.pub

Only the .pub file should be added to GitHub.

1. Generate an SSH Key

Open your terminal and run:

ssh-keygen -t ed25519 -C "your@email.com"

Replace the email with the email associated with your GitHub account.

You will be asked:

Enter file in which to save the key (/home/username/.ssh/id_ed25519):

Press Enter to use the default location.

Next, you’ll be asked for a passphrase:

Enter passphrase for "/home/username/.ssh/id_ed25519":

You can enter a passphrase to protect your private key.

You can also leave it empty by pressing Enter, but using a passphrase provides additional protection if someone gains access to your private key file.

After successful generation, you should have:

~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub

The two files are:

id_ed25519       → Private key
id_ed25519.pub → Public key

2. Verify the SSH Keys

Check your SSH directory:

ls -la ~/.ssh

You should see something similar to:

id_ed25519
id_ed25519.pub

You can also display your public key:

cat ~/.ssh/id_ed25519.pub

The output will look similar to:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... your@email.com

The entire line is your public key.

3. Add the SSH Key to the SSH Agent

The SSH agent is a background process that manages your SSH keys and can remember an unlocked private key.

This is particularly useful when your private key has a passphrase because you don’t want to manually enter that passphrase every time Git authenticates with GitHub.

Start the SSH agent:

eval "$(ssh-agent -s)"

You should see something similar to:

Agent pid 12345

Now add your private key:

ssh-add ~/.ssh/id_ed25519

If you created a passphrase, SSH will ask you for it.

After successful authentication, you should see:

Identity added: /home/username/.ssh/id_ed25519

You can verify that the key is loaded:

ssh-add -l

Your SSH key should appear in the output.

4. What If the Public Key Is Missing?

Normally, running:

ssh-keygen -t ed25519 -C "your@email.com"

creates both the private and public keys automatically.

However, suppose you already have:

~/.ssh/id_ed25519

but:

~/.ssh/id_ed25519.pub

doesn’t exist.

You can derive the public key from the existing private key.

Run:

ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pub

Then verify it:

cat ~/.ssh/id_ed25519.pub

This command does not generate a new key pair.

It reads your existing private key and derives the corresponding public key.

5. Add the Public Key to GitHub

Now we need to tell GitHub that your Linux machine is allowed to authenticate using this key.

First, display your public key:

cat ~/.ssh/id_ed25519.pub

Copy the entire line.

It should start with:

ssh-ed25519

Do not copy:

~/.ssh/id_ed25519

That is your private key.

Go to your GitHub account:

GitHub → Settings → SSH and GPG keys → New SSH key

Add a descriptive title, for example:

Linux Desktop

Paste the public key into the Key field and save it.

6. Test the GitHub SSH Connection

Before configuring Git, it’s a good idea to test SSH directly.

Run:

ssh -T git@github.com

The first time you connect, SSH may ask:

Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type:

yes

If everything is configured correctly, GitHub will respond with something similar to:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

This means your SSH authentication is working.

The message:

GitHub does not provide shell access.

is normal. It does not mean authentication failed.

7. Configure Git to Use SSH

Now let’s configure an existing Git repository to use SSH.

Inside your repository, check the current remote:

git remote -v

If you’re currently using HTTPS, you’ll see something like:

origin  https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)

Change the remote from HTTPS to SSH:

git remote set-url origin git@github.com:username/repository.git

Replace:

username
repository

with your actual GitHub username and repository name.

For example:

git remote set-url origin git@github.com:Adii9669/omaxadii.git

Verify the change:

git remote -v

You should now see:

origin  git@github.com:Adii9669/omaxadii.git (fetch)
origin git@github.com:Adii9669/omaxadii.git (push)

The important difference is:

HTTPS
https://github.com/...
SSH
git@github.com:...

8. Push Code to GitHub

Once SSH authentication and your Git remote are configured, you can use Git normally.

Get TheRandomguy’s stories in your inbox

Join Medium for free to get updates from this writer.

First, check your repository:

git status

Check your current branch:

git branch --show-current

Add your changes:

git add .

Create a commit:

git commit -m "Describe your changes"

Push your current branch:

git push -u origin HEAD

The HEAD here means the branch you are currently on.

After the branch has been connected to the remote, future pushes can usually be done with:

git push

9. Understanding the Complete Flow

Once everything is configured, the process looks like this:

Linux Machine
│
│
▼
SSH Key Pair
/ \
/ \
▼ ▼
Private Key Public Key
│ │
│ │
▼ ▼
Your Computer GitHub
│ │
│ │
└──── SSH ───────┘
│
▼
Authentication
│
▼
Git Operations
/ | \
▼ ▼ ▼
git pull git push git clone

The important relationship is:

Private key → stays on your machine
Public key → added to GitHub

10. SSH Key vs GitHub Repository

One common misunderstanding is that an SSH key belongs to a specific repository.

It doesn’t.

The SSH key is associated with your GitHub account.

For example, one SSH key can authenticate your Linux machine to multiple repositories that your GitHub account has access to:

GitHub Account
│
├── repository-A
├── repository-B
├── repository-C
└── dotfiles

You don’t need to create a separate SSH repository.

You also don’t need to put your SSH keys inside a dotfiles repository.

Your SSH keys stay in:

~/.ssh/

11. Important Security Rules

Never share your private key

Never share:

~/.ssh/id_ed25519

Don’t:

  • Upload it to GitHub
  • Commit it to a repository
  • Send it to someone
  • Put it in a public repository
  • Paste it into a public issue or forum

Public keys are meant to be shared

This file:

~/.ssh/id_ed25519.pub

is the public key and can be added to GitHub.

Protect your private key

If you use a passphrase, an attacker who obtains your private key file still needs the passphrase to use it.

12. A Note About ed25519 vs ed25519-sk

When generating an SSH key, use:

ssh-keygen -t ed25519

Do not add -sk unless you intentionally want to use a hardware security key.

For example:

ssh-keygen -t ed25519-sk

is different.

The -sk means security key and is intended for FIDO/U2F-compatible hardware authenticators such as certain YubiKey devices.

For normal GitHub SSH authentication on a Linux computer, use:

ssh-keygen -t ed25519

13. Troubleshooting

Permission denied (publickey)

If:

ssh -T git@github.com

returns:

Permission denied (publickey).

check the following:

Check that the key exists

ls -la ~/.ssh

You should have:

id_ed25519
id_ed25519.pub

Check that the key is loaded

ssh-add -l

If it isn’t loaded:

ssh-add ~/.ssh/id_ed25519

Check that the public key is on GitHub

Make sure the contents of:Commit it to a repository

cat ~/.ssh/id_ed25519.pub

were added to:

GitHub → Settings → SSH and GPG keys

Check your Git remote

git remote -v

The SSH remote should look like:

git@github.com:username/repository.git

14. Quick Setup Reference

For a future Linux installation, these are the essential commands.

Generate the key

ssh-keygen -t ed25519 -C "your@email.com"

Start the SSH agent

eval "$(ssh-agent -s)"

Add the private key

ssh-add ~/.ssh/id_ed25519

Display the public key

cat ~/.ssh/id_ed25519.pub

Add that public key to GitHub.

Test GitHub authentication

ssh -T git@github.com

Change an existing repository from HTTPS to SSH

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

Verify the remote

git remote -v

Push

git push

Final File Structure

After the setup, your SSH directory will typically look like:

~/.ssh/
├── id_ed25519
└── id_ed25519.pub

Think of them like this:

id_ed25519
│
▼
PRIVATE KEY
│
└── Keep it on your computer
Never share it
id_ed25519.pub
│
▼
PUBLIC KEY
│
└── Add it to GitHub

Once this is configured, your normal Git workflow becomes:

git pull
git add .git commit -m "message"git push

You no longer need to enter your GitHub username and password for every Git operation.

Conclusion

SSH is a one-time setup that makes GitHub authentication much more convenient on a Linux development machine.

The key things to remember are:

  1. Generate an Ed25519 SSH key pair.
  2. Keep the private key on your machine.
  3. Add the public key to GitHub.
  4. Load the private key into the SSH agent.
  5. Test the connection with ssh -T git@github.com.
  6. Configure your Git repository to use an SSH.
  7. Continue using normal Git commands such as git pull, git commit, and git push.

Once you understand the relationship between the private key, public key, SSH agent, Git, and GitHub, setting up SSH on another Linux machine becomes a straightforward process rather than something you have to troubleshoot from scratch.

--

--