← Back to list

How I Fixed My Git Authentication Issues on a VPS (So You Don’t Have To)

Setting up SSH authentication for Git on a VPS should be simple, right? Well, not always. When I tried to connect my VPS to a private Git…

Maruf H. · 2025-03-16 06:56 · 0 claps · 2.3 min read
#ssh #github #ssh-authentication #ssh-keys #vps-server
Open on Medium ↗
Wiki topics: 🔓 · Open Source

How I Fixed My Git Authentication Issues on a VPS (So You Don’t Have To)

Setting up SSH authentication for Git on a VPS should be simple, right? Well, not always. When I tried to connect my VPS to a private Git repository, I ran into a series of authentication errors, missing keys, and permission denials. If you’ve ever struggled with Git authentication on a remote server, this story will save you hours of frustration.

The Initial Roadblocks

After setting up my VPS and initializing a Git repository, I ran:

git remote add origin git@github.com:exampleuser/example-repo.git
git pull origin main

Boom! Instead of a smooth fetch, I was greeted with:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Wait, what? The repository did exist, and I had access to it. So, I tried an alternative approach with HTTPS:

git pull https://github.com/exampleuser/example-repo.git

This time, Git asked for my username and password. Not ideal, but I entered my credentials. And yet, GitHub rejected it! Turns out, GitHub had disabled password authentication in favor of personal access tokens.

Switching to SSH Authentication

Realizing that SSH was the way to go, I checked my SSH directory:

ls -la ~/.ssh/

It showed multiple SSH keys:

-rw------- 1 root root 3401 id_rsa
-rw-r--r-- 1 root root  757 id_rsa.pub
-rw------- 1 root root 432  id_ed25519
-rw-r--r-- 1 root root 113  id_ed25519.pub

Since GitHub prefers Ed25519 keys (for better security and performance), I decided to use it.

Here’s the corrected and well-structured version of your process:

🔑 Generating a New SSH Key

I created a new SSH key specifically for Git authentication:

ssh-keygen -t ed25519 -C "my-vps@example.com"

📌 After running the command:

It prompted me to enter a file name where the key should be saved:

Enter file in which to save the key (/root/.ssh/id_ed25519): /root/.ssh/new-key-name
  • If I didn’t provide a name, it generated:
  • id_ed25519 (private key)
  • id_ed25519.pub (public key)
  • If I specified a name (new-key-name), it generated:
  • new-key-name (private key)
  • new-key-name.pub (public key)

🖥️ Adding the SSH Key to the SSH Agent

To use the new key, I started the SSH agent and added the key:

eval "$(ssh-agent -s)"

Then, I added the key to the agent:

ssh-add ~/.ssh/id_ed25519       # Default key  
ssh-add ~/.ssh/new-key-name     # Custom key (if named differently)

🔗 Adding the SSH Key to GitHub

To ensure GitHub recognized my key, I copied the public key:

cat ~/.ssh/id_ed25519.pub        # Default key  
cat ~/.ssh/new-key-name.pub      # Custom key

I then logged into GitHub → Settings → SSH and GPG Keys and added the key as an Authentication Key.

Done! Now, I can securely authenticate with GitHub via SSH. 🚀

To verify my setup, I ran:

ssh -T git@github.com

Success! GitHub responded:

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

Updating Git Remote and Pulling Code

Finally, I set the correct Git remote URL:

git remote set-url origin git@github.com:exampleuser/example-repo.git

Then, I pulled the latest code:

git pull origin main

And it worked! 🎉

Lessons Learned

  1. Use SSH instead of HTTPS for GitHub authentication.
  2. Generate an Ed25519 SSH key instead of RSA for better security.
  3. Ensure your SSH key is added to GitHub under SSH settings.
  4. Use ssh -T git@github.com to verify authentication.
  5. Check your Git remote URL to confirm you’re using SSH.

Conclusion

What started as a simple Git setup turned into a troubleshooting adventure. But by understanding SSH keys and authentication, I now have a secure and efficient way to manage my repositories. Hopefully, this guide helps you avoid the same pitfalls!

Have you faced similar Git authentication struggles? Let me know in the comments! 🚀


메타데이터
post_id
9ff928be33e1
slug
how-i-fixed-my-git-authentication-issues-on-a-vps-so-you-dont-have-to-9ff928be33e1
url
https://medium.com/@maruf.mhb/how-i-fixed-my-git-authentication-issues-on-a-vps-so-you-dont-have-to-9ff928be33e1
canonical_url
https://medium.com/@maruf.mhb/how-i-fixed-my-git-authentication-issues-on-a-vps-so-you-dont-have-to-9ff928be33e1
author_url
https://medium.com/@maruf.mhb
status
ok
fetched_at
2026-06-21 23:24:37