Adding a SSH key to an VPN

Trying to clone a git repo in your VPS and getting Permission denied?

Adding a SSH key to an VPN
  1. Home
  2. Blog
  3. Adding a SSH key to an VPN

Are trying to clode a git repo into your private or VPS server and getting this error:

root@XXX:~# git clone git@github.com:USER/PROJECT.git Cloning into 'XXX'... git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

This error indicates that your VPS does not have access to the repository via SSH, meaning that GitHub does not recognise your server's public key. Let's go through the steps to fix this:

1. Check if your VPS has an SSH key

Run

ssh-keygen -t ed25519 -C "your_email@example.com"

If you don’t see files like id_rsa or id_ed25519, it means no SSH key has been generated yet.

2. Generate a new SSH key (if none exists)

ssh-keygen -t ed25519 -C "your_email@example.com"
  • Press Enter to accept the default path (/root/.ssh/id_ed25519)
  • Optional: add a passphrase or leave it empty.

Then make sure the SSH agent is running:

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

3. Add the public key to GitHub

First, copy the public key:

cat ~/.ssh/id_ed25519.pub

Then go to GitHub → Settings → SSH and GPG keys → New SSH key and paste the key.

4. Test the connection to GitHub

ssh -T git@github.com

If it works, you’ll see something like:

git clone git@github.com:albertofortes/accessiblAI.git

5. Clone the repository

Now you can run:

git clone git@github.com:[USER]/[PROJECT].git
```
It should work without any issues.