Issue
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
- Run
ssh-keygen -t rsa -b 4096 -C "[email protected]"
these are then saved as id_rsa and id_rsa.pub in ~/.ssh/ - The deployment public key (id_rsa.pub) is added on the GitHub online UI in the deployment keys section
- The directory is already cloned in /var/www/ directory, this is working all good via HTTPS for pulling
- 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.
Solution
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:
- give your user/group write access to
/var/www
- run the pull/clone as the user, not the root user.
Answered By - OneOfOne