If you're using Git and GitHub on Ubuntu, setting up SSH authentication is a useful step. It allows you to connect your local machine to GitHub securely without entering your GitHub credentials every time you push or pull code.
While setting up SSH on my Ubuntu machine, I made a small mistake when generating the SSH key. Instead of accepting the default file location, I entered a custom name.
This article explains what I did, what went wrong, and how I fixed it.
What Is SSH?
SSH stands for Secure Shell. It is a secure way of connecting and authenticating between computers.
With GitHub, SSH allows your local machine to authenticate with your GitHub account.
Instead of using an HTTPS URL like:
https://github.com/username/repository.git
you can use an SSH URL:
git@github.com:username/repository.git
Once SSH is configured, commands such as:
git clone
git pull
git push
can communicate with GitHub using your SSH key.
Step 1: Generate an SSH Key
On Ubuntu, open your terminal and run:
ssh-keygen -t ed25519 -C "your-email@example.com"
For example:
ssh-keygen -t ed25519 -C "vincenttommikorir@gmail.com"
You should see something similar to:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/backend-developer/.ssh/id_ed25519):
The important part
At this point, SSH is asking where you want to save the key.
The recommended approach for a first setup is simply to press Enter.
That will use the default location:
/home/backend-developer/.ssh/id_ed25519
You will then have:
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
The first file is your private key.
The second file is your public key.
A Mistake I Made
When I generated my key, I entered:
Tommi
when SSH asked:
Enter file in which to save the key (/home/backend-developer/.ssh/id_ed25519):
SSH therefore created:
~/Tommi
~/Tommi.pub
instead of:
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
The key itself was still valid. It was simply saved in a different location.
This is an important lesson: entering a filename at that prompt changes where SSH saves the key.
Step 2: Check Where Your Key Was Saved
If you accidentally entered a custom name, you can check your home directory:
ls -l ~/Tommi*
You may see:
/home/backend-developer/Tommi
/home/backend-developer/Tommi.pub
This confirms that the key exists.
Step 3: Move the Key to the .ssh Directory
The .ssh directory is the standard location for SSH keys.
If your files are currently:
~/Tommi
~/Tommi.pub
you can move them using:
mv ~/Tommi ~/.ssh/id_ed25519
mv ~/Tommi.pub ~/.ssh/id_ed25519.pub
Now your files should be:
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
You can check them with:
ls -la ~/.ssh
Step 4: Set the Correct Permissions
SSH keys should have appropriate file permissions.
Run:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
The private key should be readable only by your user.
That's why we use:
chmod 600 ~/.ssh/id_ed25519
Your public key can have less restrictive permissions:
chmod 644 ~/.ssh/id_ed25519.pub
Step 5: Start the SSH Agent
The SSH agent helps manage your private keys.
Start it with:
eval "$(ssh-agent -s)"
You should get something similar to:
Agent pid 38799
The process ID will be different on different systems.
Step 6: Add Your SSH Key to the Agent
Run:
ssh-add ~/.ssh/id_ed25519
If you created a passphrase for your key, you may be asked to enter it.
You can verify that the key has been added:
ssh-add -l
You should see your key fingerprint.
For example:
256 SHA256:AR9yA2U3it1bo5y6erYw/yg/XLsQr8CX/wKw+hw/XAQ
Step 7: Get Your Public Key
Now display your public key:
cat ~/.ssh/id_ed25519.pub
It should look similar to:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... your-email@example.com
Copy the entire line.
Important Security Note
There are two files:
id_ed25519
id_ed25519.pub
The difference is important.
Private key
id_ed25519
Never share this file with anyone.
Public key
id_ed25519.pub
This is the key you add to GitHub.
You can share your public key, but keep your private key secret.
Step 8: Add the Public Key to GitHub
Log in to GitHub and go to:
Settings → SSH and GPG keys → New SSH key
Give the key a recognizable title, for example:
Lenovo X390 Ubuntu
Select:
Authentication Key
Then paste the contents of:
cat ~/.ssh/id_ed25519.pub
into the key field.
Save the key.
Step 9: Test the GitHub SSH Connection
Now test the connection:
ssh -T git@github.com
The first time you connect, you may see:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type:
yes
If everything is configured correctly, GitHub should 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.
Step 10: Use SSH When Cloning Repositories
Once SSH is configured, use the SSH repository URL when cloning.
Instead of:
git clone https://github.com/username/repository.git
use:
git clone git@github.com:username/repository.git
For example:
git clone git@github.com:vincenttommi/my-project.git
What If I Already Have a Git Repository?
If you already cloned a project using HTTPS, check the remote URL:
git remote -v
You might see:
origin https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)
You can change it to SSH:
git remote set-url origin git@github.com:username/repository.git
Then check again:
git remote -v
You should now see:
origin git@github.com:username/repository.git (fetch)
origin git@github.com:username/repository.git (push)
You can then use:
git pull
and:
git push
using SSH authentication.
Common Mistake: "No Such File or Directory"
One error I encountered was:
cat: /home/backend-developer/.ssh/id_ed25519.pub: No such file or directory
This happened because I had saved the key as:
Tommi
rather than accepting the default:
~/.ssh/id_ed25519
I also tried:
cat ~/.ssh/id_Tommi.pub
but that didn't work either because the file wasn't saved as id_Tommi.pub.
The actual file was:
~/Tommi.pub
The lesson is to check where SSH actually created the files instead of assuming their names.
Useful Commands
Here are the main commands from this setup:
Generate a key
ssh-keygen -t ed25519 -C "your-email@example.com"
Check SSH files
ls -la ~/.ssh
Start SSH agent
eval "$(ssh-agent -s)"
Add your key
ssh-add ~/.ssh/id_ed25519
List keys loaded into the agent
ssh-add -l
Display public key
cat ~/.ssh/id_ed25519.pub
Test GitHub
ssh -T git@github.com
Check Git remote
git remote -v
Change an HTTPS remote to SSH
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Final Thoughts
Setting up SSH with GitHub is straightforward once you understand the difference between the private key, public key, and SSH agent.
The biggest lesson I learned from my setup was not to overlook this prompt:
Enter file in which to save the key (/home/username/.ssh/id_ed25519):
If you're not sure what to enter, simply press Enter and use the default location.
If you accidentally save the key somewhere else, don't panic. The key is still usable—you can move it into the .ssh directory and configure it correctly.
Learning from small mistakes like this is part of working with Linux and development tools. Documenting these problems can also help another developer who runs into the same issue.
Happy coding!
Top comments (0)