【问题标题】:can't push to github repo after replasing to another PC替换到另一台 PC 后无法推送到 github repo
【发布时间】:2014-01-10 07:34:44
【问题描述】:

我正在启动我的项目并使用 github 进行远程 repo。

我将操作系统从 Ubuntu 更改为 Xubuntu。

但我将所有旧文件都复制到了新位置。

我一直在使用我需要推送更改的程序。

我生成了新的 SSH 密钥并添加到了 github。

我尝试推送更改,但它打印出奇怪的信息:

nazar@nazar-desctop:~/Documents/workspace/NewYearGift$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
nazar@nazar-desctop:~/Documents/workspace/NewYearGift$ sudo git push -u origin master
[sudo] password for nazar:
ssh: Could not resolve hostname github.com: Name or service not known
fatal: The remote end hung up unexpectedly

更新:

我再次重新创建了这个项目,现在它询问我的密码:

nazar@nazar-desctop:~/Documents/workspace/NewYearGift$ git commit -m "correct smole issue"
[master e2cbdec] correct smole issue
 1 file changed, 29 insertions(+), 29 deletions(-)
 rewrite README.md (89%)
nazar@nazar-desctop:~/Documents/workspace/NewYearGift$ git push
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Enter passphrase for key '/home/nazar/.ssh/id_rsa': 
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 843 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@github.com:nazar-art/NewYearGift.git
   3fb0853..e2cbdec  master -> master

现在可以了,但为什么这么严格?

smb能解释一下吗?

如何解决这个问题?

【问题讨论】:

    标签: git github ssh xubuntu


    【解决方案1】:

    创建 SSH 密钥时,您可以选择为其添加密码。这不是强制性的,但它确实提供了额外的安全层。

    系统提示您输入密码,因为您的密钥已有密码。

    如果您愿意,可以删除密码,但我建议您改用 agent。使用代理时,只需输入一次密码,一定时间内不会被提升再次输入。

    根据您的操作系统和桌面环境,您有多种运行代理的选项。 OpenSSH 提供了这种方法:

    ssh-add -t 5h
    

    这将立即提示您输入密码,然后让您工作五个小时,而无需重新输入密码。详情请见manpage

    OpenSSH 所理解的时间格式可以在manpage for sshd_config 中找到。

    【讨论】:

    • 5h 表示 5 小时还是 5 天?
    • @nazar_art 是的,我链接到的联机帮助页指向 sshd_config 的联机帮助页,lists time formats。我将编辑我的答案以包含此信息。
    • 最好改为几周
    • 如果你真的想要你可以完全省略-t <duration>。只要您登录,代理就会保持活动状态。
    【解决方案2】:

    确保您的 ssh 网址不是 one using an scp syntax:

    github.com:username/yourRepo
    

    因为如果是,ssh 会寻找~/.ssh/config 文件来解析“github.com

    Host github.com
      HostName github.com
      User git
    

    你可以使用原来的ssh url:

    git remote set-url origin ssh://git@github.com/username/yourRepo.git
    

    您也可以尝试切换到 https 网址

    git remote set-url origin https://username@github.com/username/yourRepo
    

    【讨论】:

      【解决方案3】:

      无法解析主机名 github.com:名称或服务未知

      您需要修复系统的解析器。由于某种原因,它无法解析 github.com 的 IP 地址

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-29
        • 1970-01-01
        • 2011-03-20
        • 1970-01-01
        • 1970-01-01
        • 2018-02-27
        • 1970-01-01
        相关资源
        最近更新 更多