【问题标题】:Git remote push not working, SSH key issuesGit远程推送不起作用,SSH密钥问题
【发布时间】:2015-11-10 13:12:27
【问题描述】:

我有一个要推送到的 Amazon EC2 网络服务器。它的 SSH 连接使用没有密码的密钥进行身份验证。我已经像这样设置了本地机器的 ssh 配置文件

Host web                                                                        
Hostname <path to host>                                                           
User ubuntu                                                                     
IdentityFile <path to key>                                   
IdentitiesOnly yes

当我这样做时

ssh web

我登录很好,但是当我尝试这样做时

git push web

我明白了

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

在本地机器上和

Connection closed by <local machine's IP> [preauth]

在服务器上的 ssh auth.log 文件中。我一直在服务器和本地上一遍又一遍的 SSH 和 git 文件,我就是无法得到它。我可能会错过什么?

.git 配置在本地是

[core]                                                                          
    repositoryformatversion = 0                                             
    filemode = true                                                         
    bare = false                                                            
    logallrefupdates = true                                                 
[remote "origin"]                                                               
    url = https://<bitbucketpath>.git    
    fetch = +refs/heads/*:refs/remotes/origin/*                             
[branch "master"]                                                               
    remote = origin                                                         
    merge = refs/heads/master                                                 
[remote "web"]                                                                  
    url = ubuntu@<server ip>:/home/ubuntu/git/test.git                  
    fetch = +refs/heads/*:refs/remotes/web/*         

repo 归 ubuntu 所有,ubuntu 是配置中指定的通过 ssh 登录的用户。

【问题讨论】:

  • 您的网址以 https:// 开头,但您正在研究 ssh 身份验证。我猜你想要ssh://
  • 那是起源,我说的是网络遥控器。除非那很重要?
  • 哦,是的,我明白了。我会很明确(ssh://user@addr/home/...),但它应该在那里默认为 ssh,是的(因此不重要)。

标签: git ssh amazon-ec2 ssh-keys git-remote


【解决方案1】:

您的 ssh 配置块以 Host web 开头。当你用 ssh 测试它时,你运行命令ssh web。 SSH 在 ssh 配置文件中查找“web”条目并使用这些参数。

然而,在 git 中你的遥控器是

[remote "web"]                                                                  
    url = ubuntu@<server ip>:/home/ubuntu/git/test.git                  
    fetch = +refs/heads/*:refs/remotes/web/*         

在这里,您使用的不是主机名,而是 IP 地址。您需要更新您的 ssh 配置,以便它知道为此 IP 地址使用所需的参数,而不仅仅是主机名“web”。只需将 IP 添加到您的 Host 条目即可。

Host web 1.2.3.4

(显然,用真实IP地址代替1.2.3.4。)

【讨论】:

  • 这似乎已经解决了!奇怪的是我看过的教程没有提到这一点。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-28
  • 2013-10-12
  • 2013-06-22
  • 1970-01-01
  • 2014-05-14
  • 2021-07-25
  • 1970-01-01
相关资源
最近更新 更多