Adding a SSH key to an VPN
2025-09-19
Trying to clone a git repo in your VPS and getting Permission denied?
Are trying to clode a git repo into your private or VPS server and getting this error:
1root@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
1ssh-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)
1ssh-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:
1eval "$(ssh-agent -s)" 2ssh-add ~/.ssh/id_ed25519
3. Add the public key to GitHub
First, copy the public key:
1cat ~/.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
1ssh -T git@github.com
If it works, you’ll see something like:
1git clone git@github.com:albertofortes/accessiblAI.git
5. Clone the repository
Now you can run:
1git clone git@github.com:[USER]/[PROJECT].git 2``` 3It should work without any issues.
