How to Set Up SSH Authentication for GitHub on Linux
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 AccountThe 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_ed25519Your public key will normally be:
~/.ssh/id_ed25519.pubOnly 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.pubThe two files are:
id_ed25519 → Private key
id_ed25519.pub → Public key2. Verify the SSH Keys
Check your SSH directory:
ls -la ~/.sshYou should see something similar to:
id_ed25519
id_ed25519.pubYou can also display your public key:
cat ~/.ssh/id_ed25519.pubThe output will look similar to:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... your@email.comThe 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 12345Now add your private key:
ssh-add ~/.ssh/id_ed25519If you created a passphrase, SSH will ask you for it.
After successful authentication, you should see:
Identity added: /home/username/.ssh/id_ed25519You can verify that the key is loaded:
ssh-add -lYour 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_ed25519but:
~/.ssh/id_ed25519.pubdoesn’t exist.
You can derive the public key from the existing private key.
Run:
ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pubThen verify it:
cat ~/.ssh/id_ed25519.pubThis 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.pubCopy the entire line.
It should start with:
ssh-ed25519Do not copy:
~/.ssh/id_ed25519That 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 DesktopPaste 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.comThe first time you connect, SSH may ask:
Are you sure you want to continue connecting (yes/no/[fingerprint])?Type:
yesIf 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 -vIf 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.gitReplace:
username
repositorywith your actual GitHub username and repository name.
For example:
git remote set-url origin git@github.com:Adii9669/omaxadii.gitVerify the change:
git remote -vYou 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 statusCheck your current branch:
git branch --show-currentAdd your changes:
git add .Create a commit:
git commit -m "Describe your changes"Push your current branch:
git push -u origin HEADThe 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 push9. 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 cloneThe important relationship is:
Private key → stays on your machine
Public key → added to GitHub10. 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
└── dotfilesYou 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_ed25519Don’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.pubis 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 ed25519Do not add -sk unless you intentionally want to use a hardware security key.
For example:
ssh-keygen -t ed25519-skis 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 ed2551913. Troubleshooting
Permission denied (publickey)
If:
ssh -T git@github.comreturns:
Permission denied (publickey).check the following:
Check that the key exists
ls -la ~/.sshYou should have:
id_ed25519
id_ed25519.pubCheck that the key is loaded
ssh-add -lIf it isn’t loaded:
ssh-add ~/.ssh/id_ed25519Check that the public key is on GitHub
Make sure the contents of:Commit it to a repository
cat ~/.ssh/id_ed25519.pubwere added to:
GitHub → Settings → SSH and GPG keys
Check your Git remote
git remote -vThe SSH remote should look like:
git@github.com:username/repository.git14. 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_ed25519Display the public key
cat ~/.ssh/id_ed25519.pubAdd that public key to GitHub.
Test GitHub authentication
ssh -T git@github.comChange an existing repository from HTTPS to SSH
git remote set-url origin git@github.com:USERNAME/REPOSITORY.gitVerify the remote
git remote -vPush
git pushFinal File Structure
After the setup, your SSH directory will typically look like:
~/.ssh/
├── id_ed25519
└── id_ed25519.pubThink of them like this:
id_ed25519
│
▼
PRIVATE KEY
│
└── Keep it on your computer
Never share it
id_ed25519.pub
│
▼
PUBLIC KEY
│
└── Add it to GitHubOnce this is configured, your normal Git workflow becomes:
git pullgit 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:
- Generate an Ed25519 SSH key pair.
- Keep the private key on your machine.
- Add the public key to GitHub.
- Load the private key into the SSH agent.
- Test the connection with
ssh -T git@github.com. - Configure your Git repository to use an SSH.
- Continue using normal Git commands such as
git pull,git commit, andgit 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.





