【问题标题】:Why can't git resolve the hostname when I push to a valid SSH address?当我推送到有效的 SSH 地址时,为什么 git 无法解析主机名?
【发布时间】:2012-12-17 10:28:37
【问题描述】:

我正在 Heroku 上部署一个应用程序,所以我从一个 repo 创建了一个 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 用户名和密码。
  • @MichaelDurrant 嗯...我收到此错误:fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
  • 好的,现在请输入git remote show
  • 哦,请确保您位于应用程序的根目录中 - 所以请在命令行输入 pwd
  • @MichaelDurrant 好的。我以前是这样做的。 heroku 有一套遥控器

标签: git heroku ssh ssh-keys git-remote


【解决方案1】:

git@heroku.com:heroku-app.git 是此 ssh 地址的 SCP format

它依赖于带有“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 替换为xxxgit push xxx:heroku-app.git,前提是您在~/.ssh/config 文件中有xxx 条目。

【讨论】:

  • 啊...这完全有道理。我认为配置文件可能有问题,但我以前从未使用过它。非常感谢!!!
  • @chromedude 不客气。不要忘记您不需要在“git@heroku.com:...”中使用“git”,因为在~/.ssh/config 文件中指定了用户“git”。所以git push heroku:heroku-app.git 就足够了(我会推荐一个名为heroku 的条目,而不是heroku.com,只是为了确保不要将它与主机名混合)
  • 好的。是的,这是有道理的。
【解决方案2】:

也可以这么简单:

  1. $ heroku 登录
  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 之间没有名称冲突)

【讨论】:

    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 2017-12-04
    • 2018-12-04
    相关资源
    最近更新 更多