I have ec2 server with ubuntu 12.04, I have added one more user "git" to server. Generated ssh key and uploaded to both users .ssh directory. So now i can access my server as
ssh ubuntu@example.com
ssh git@example.com
I have created a bare repository to /opt/git/gitpg.git
and added this as remote to my local repository as
sudo git remote add deploy ubuntu@example.com:/opt/git/gitpg.git
When i tried to push to this repository, it shows authentication error.
sudo git push deploy master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I also tried this solution, but it also doesn't work.
Can anyone please suggest what may be the possible reason ?
Update
When i tried git push deploy master
instead of sudo git push deploy master
it succeed to connect but unable to push due to permission.
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 356 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To ubuntu@example.com:/opt/git/gitpg.git
d6cc9c3..25ddaa4 master -> master
error: unable to create directory for .git/refs/remotes/deploy/master
error: Cannot lock the ref 'refs/remotes/deploy/master'.
Update 2
I changed local directory permission to current user now it working without sudo. But i still don't know why it is nor working with sudo.