重播到另一台PC后无法推送到github repo

时间:2013-12-21 15:31:58

标签: git github ssh xubuntu

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

我将操作系统从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

现在它有效,但为什么这么严格?

可以解释一下吗?

如何解决这个问题?

3 个答案:

答案 0 :(得分:2)

  

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

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

答案 1 :(得分:1)

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

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

如果需要,可以删除密码,但我建议使用代理。使用代理时,您可以提供一次密码短语,并且在一段时间内不会再次提示您输入密码短语。

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

ssh-add -t 5h

这会立即提示您输入密码,然后让您工作五个小时而无需重新输入密码。有关详细信息,请参阅manpage

OpenSSH理解的时间格式可以在manpage for sshd_config

中找到

答案 2 :(得分:0)

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

github.com:username/yourRepo

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

Host github.com
  HostName github.com
  User git

您可以使用原始的ssh网址:

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

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

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