Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ssh将git推送到服务器,公钥错误_Git_Ssh_Amazon Ec2_Ubuntu 12.04 - Fatal编程技术网

使用ssh将git推送到服务器,公钥错误

使用ssh将git推送到服务器,公钥错误,git,ssh,amazon-ec2,ubuntu-12.04,Git,Ssh,Amazon Ec2,Ubuntu 12.04,我有带ubuntu 12.04的ec2服务器,我在服务器上又添加了一个用户“git”。生成ssh密钥并上载到两个users.ssh目录。因此,现在我可以访问我的服务器作为 ssh ubuntu@example.com ssh git@example.com 我已经为/opt/git/gitpg.git创建了一个裸存储库,并将其作为远程文件添加到本地存储库中 sudo git remote add deploy ubuntu@example.com:/opt/git/gitpg.git 当我尝

我有带ubuntu 12.04的ec2服务器,我在服务器上又添加了一个用户“git”。生成ssh密钥并上载到两个users.ssh目录。因此,现在我可以访问我的服务器作为

ssh ubuntu@example.com
ssh git@example.com
我已经为
/opt/git/gitpg.git
创建了一个裸存储库,并将其作为远程文件添加到本地存储库中

sudo git remote add deploy ubuntu@example.com:/opt/git/gitpg.git
当我尝试推送到这个存储库时,它显示身份验证错误

sudo git push deploy master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我也试过了,但也没用

有人能提出可能的原因吗

更新

当我尝试
git-push-deploy-master
而不是
sudo-git-push-deploy-master
时,它成功连接,但由于权限原因无法推送

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'.
更新2

我将本地目录权限更改为当前用户,现在它可以在没有sudo的情况下工作。
但是我仍然不知道为什么它不能与sudo一起工作。

尝试将您的公钥放在服务器的
.ssh/authorized\u keys
中,或者使用其他类似的协议:

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

您确定已将生成的正确公钥放入git服务器吗?我可以登录,而无需将pem文件定义为sshubuntu@example.comAre当你通过ssh登录时,你可以在服务器上创建目录吗?@Banago,是的,我已经将chown交给ubuntu用户进行了裸repo。谢谢@Banago,当我使用ssh://时,它说ssh:
无法解析hostname example.com::Name或service not known
是的,我在示例上加了一个冒号。只有在指定端口时才需要它。