afkplus afkplus - 3 months ago 7
Linux Question

GitHub SSH access not working

I have created a new user on github under our organization which will be used for auto deployment. I followed the article on

Somehow, when I tried to clone the repository to the server, it worked once. The code was running properly, and I exit the server. Today, we released an update to the code, and I wanted to deploy the code manually to the server, so I ssh'd into the server and tried to pull the repository with

git pull
. It gave me Permission denied error. After some debugging I realized that the ssh-agent wasn't running. So I executed the following commands:

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

Now, when I try
ssh -T
, I see the welcome message which is:

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

But when I try to pull from the repository, I am continuously getting this error message:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I checked the repository and the user has read access to it. I double checked if the keys match on github and server, yes they do. I tried generating new keys. I tried using ssh/config file. Nothing helped...

I appreciate any help & suggestions!


So I figured out that
git clone
command is working properly, but even when I try
git pull
right after git clone, it is giving the error.


If you are using sudo to git pull/push to the remote you need to ensure you used sudo to generate your SSH keys. Otherwise you will not be using the same keys that you originally generated.

github doc for reference