为什么我在推送到一个有效的SSH地址时,Git无法解析主机名?

7
我正在Heroku上部署一个应用程序,我从存储库创建了一个Heroku应用程序,然后执行了git push heroku master。但是每次执行此操作时,都会出现以下错误:
!  Your key with fingerprint xxx is not authorized to access heroku-app.

fatal: Could not read from remote repository.

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

我尝试了各种方法来更改我的SSH密钥,包括删除它们并创建新的。但仍然出现相同的错误。我已将密钥添加到Heroku。

然后我尝试运行ssh -vT git@heroku.com:heroku-app.git,结果如下:

OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
ssh: Could not resolve hostname heroku.com:heroku-app.git: nodename nor servname provided, or not known

我无法确定错误指向的是什么。主机名绝对有效。我是否缺少SSH配置文件中所需的内容?如果有任何想法,那就太棒了,因为我今天花了很多时间尝试让它工作,但没有成功。


如果我用ssh的方式进行操作,会出现相同的错误。所以请尝试这样做:执行 git remote show origin 命令。您需要输入您的Github用户名和密码。 - Michael Durrant
好的,请输入 git remote show - Michael Durrant
哦,请确保你在应用程序的根目录下 - 因此请在命令行中键入 pwd - Michael Durrant
@MichaelDurrant 好的。我以前就做过这个。Heroku有一个远程设置。 - chromedude
请执行 ssh -T git@github.com - Michael Durrant
显示剩余3条评论
2个回答

9

git@heroku.com:heroku-app.git 是此 SSH 地址的 SCP 格式

它依赖于一个带有 'heroku.com' 条目的 ~/.ssh/config 文件,该文件指定用户、实际主机名,以及必要时的私钥/公钥路径。

host heroku.com
     user git
     hostname heroku.com
     identityfile ~/.ssh/yourPrivateKey

再次说明:在“heroku.com: heroku-app.git”中,“heroku.com”不是主机名,而是ssh配置文件中的一个条目。您可以通过将“heroku.com”替换为“xxx”来执行此操作:“git push xxx:heroku-app.git”,前提是您在“~/.ssh/config”文件中有一个“xxx”条目。

啊...这很有道理。我以为配置文件可能有问题,但我以前从未使用过它。非常感谢!!! - chromedude
2
@chromedude 非常欢迎。不要忘记在“git@heroku.com:...”中不需要使用“git”,因为用户“git”已在~/.ssh/config文件中指定。所以一个git push heroku:heroku-app.git就足够了(我建议使用名为“heroku”的条目,而不是“heroku.com”,以确保不与主机名混淆)。 - VonC

0

它也可以很简单:

  1. $ heroku login
  2. $ heroku git:clone -a appname (这一行对我很有帮助)
  3. $ git add .
  4. $ git commit -am "让它更好"
  5. $ git push heroku master

在确保$ heroku git:remote -a appname(heroku和git之间没有名称冲突)后


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接