【问题标题】:Cannot push to github at any repository无法在任何存储库中推送到 github
【发布时间】:2014-02-27 08:53:45
【问题描述】:

这很奇怪,但我无法将任何存储库(和新存储库)提交到 github。 我已将我的 ssh-key 上传到 github。

demas@demas-home:~/dotfiles$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.

嗨,demas!您已成功通过身份验证,但 GitHub 不提供 shell 访问权限。

现在我创建一个新的存储库并尝试将第一个提交推送到 github:

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/demas/netrunner.git
git push -u origin master

但是 github 会询问我的用户名和密码。为什么?

即使我输入了我的用户名和密码,我也会收到错误:

demas@demas-home:~/netrunner$ git push -u origin master
Username for 'https://github.com': demas
Password for 'https://demas@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/demas/netrunner.git/'

如果重要,我会使用双因素身份验证。

【问题讨论】:

标签: git github


【解决方案1】:

问题出在这一行

git remote add origin https://github.com/demas/netrunner.git

当尝试通过 http 协议访问服务器时,git 不使用您的 ssh 密钥(据我所知,在这种情况下使用基本的 http 身份验证)。使用 ssh 访问(url 看起来像 git@github.com:username/reponame.git)

【讨论】:

    【解决方案2】:

    解决这个问题的最简单方法是使用 ssh url 克隆你的 git repo 进入一个新目录并在那里工作。

    【讨论】:

    • 废话。如果您对 repo 有推送权限,则 GitHub HTTPS 是可读写的。问题是 a) OP 使用 2fa,因此他需要输入令牌而不是密码 b) 他想使用 SSH 但使用的是 HTTPS url
    猜你喜欢
    • 2021-11-27
    • 2017-08-22
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2018-05-02
    • 2011-12-09
    • 2019-06-18
    • 2021-01-08
    相关资源
    最近更新 更多