Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remote pull using GitHub deployment keys - Permission Denied

I have done the following steps to setup ssh deployment keys with our git repo for it to be able to git pull without a username and password:

Note: I am on AWS EC2 / Ubuntu 14.04.3

  1. Run ssh-keygen -t rsa -b 4096 -C "[email protected]" these are then saved as id_rsa and id_rsa.pub in ~/.ssh/
  2. The deployment public key (id_rsa.pub) is added on the GitHub online UI in the deployment keys section
  3. The directory is already cloned in /var/www/ directory, this is working all good via HTTPS for pulling
  4. Try sudo git pull [email protected]:ownersUsername/OurRepo.git and get the following error

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

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

Another Note: This repository is private under another users account.

Also, when I try ssh [email protected] I get:

Hi userName/Repo! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.

And the deployment key comes up as being used. Have been on this issue for greater than 4 hours now and any would would be very much appreciated, thanks.

like image 686
James Marino Avatar asked Apr 29 '16 12:04

James Marino


1 Answers

The problem is you're using sudo, which runs the command as root, and it will try to use the root's keys not your user's keys.

What you want to do is:

  1. give your user/group write access to /var/www
  2. run the pull/clone as the user, not the root user.
like image 114
OneOfOne Avatar answered Sep 24 '22 07:09

OneOfOne