简体   繁体   中英

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 https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux .

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 git@github.com , 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!


Update:

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

I had the exact same issue. For me what worked was

  1. Go to repo on github which you have cloned and wanna pull with
  2. Under the code-download option copy SSH link
  3. Enter following command in your terminal --> git remote set-url origin paste_SSH_link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM