我无法推送到我的Amazon EC2实例上存储的远程git仓库。SSH可以进入服务器,但不是git push
我的本地ssh
config
文件中有一个主机条目,看起来像这样:
Host ec2
HostName ec2-54-89-205-210.compute-1.amazonaws.com
User ec2-user
IdentityFile ~/.ssh/ec2TestB
而且这样我就可以运行该命令ssh ec2
,我会成功连接到ec2
。
接下来,我在名为testGitRoot
的root
文件夹中的ec2
上创建了git repo
。在我的本地机器上,我创建了一个git repo
,名为testGitLocal
。然后我添加ec2
repo
与git remote add origin [email protected]:/root/testGitRoot
(我也试过没有[email protected]
部分..不知道是否需要)。
位当我运行git push origin master
我得到:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
所以我的问题是什么概念,我错过了?如果我能通过ssh与ssh ec2
进行连接,那么为什么我不能推回我的回购?有一件事情我不清楚的是,我甚至使用了ssh
来完成git设置步骤。通常情况下,我总是推送到github,在这种情况下,我采取ssh
网址并将其设置为我的远程。在这种情况下,我只是将我的ec2
repo
设置为远程,其URL只是ec2Domain:path/to/git/repo
。所以即使git push origin master
使用ssh
,如果是的话,为什么它似乎是在ssh ec2
命令不失败时公钥失效?
我使用的(我认为)CentOS的AMI,所以我敢肯定的是,用户是'ec2user'。我不确定在'git remote add origin'中是否需要'user @'语法。基本上是''?或' @'?我也不知道哪个密钥对是正确的。我已经安装了两个git代表,并简单地将远程作为源名添加到域名中。正如我在我的问题中所说,我甚至不确定如果它使用ssh。 –
'git remote add origin $ URL'。如果你使用ssh类型的URL,git将使用ssh。请参阅[git URL](https://git-scm.com/docs/git-fetch#_git_urls_a_id_urls_a)。 – phd