简体   繁体   中英

git push with ssh to server , public key error

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.

尝试将您的公共密钥放在.ssh/authorized_keys中的服务器中,或使用其他类似的协议:

ssh://ubuntu@example.com/opt/git/gitpg.git

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