James
James

Reputation: 708

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.

Upvotes: 6

Views: 9090

Answers (2)

OneOfOne
OneOfOne

Reputation: 99224

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.

Upvotes: 8

CodeWizard
CodeWizard

Reputation: 142064

When you do a git pull you don't need the link.

git pull <remote> <branch>

You need the full url for the clone command

sudo git clone [email protected]:ownersUsername/OurRepo.git

To test if your ssh key is good use this:

git fetch --all --prune

Upvotes: 0

Related Questions