【问题标题】:Github authentication error when trying to push on command line (SSH key added in Github)尝试在命令行上推送时出现 Github 身份验证错误(在 Github 中添加了 SSH 密钥)
【发布时间】:2021-06-07 18:41:27
【问题描述】:

我已生成我的 SSH 密钥并将其添加到 Github。

现在我正在尝试编写一个脚本,在 Github 中生成一个新的私有存储库并上传初始文件。系统将提示用户输入新存储库的名称。

下面给出了我的代码。问题是尝试将文件推送到 Github 时出现以下错误

ssh: Could not resolve hostname github.com:rongardF: Name or service not known
fatal: Could not read from remote repository.

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

为什么会出现此错误?我还有什么需要做的吗?

代码:

@echo off
set /p name="Enter new project name: "

touch README.md
touch .gitignore
echo __Previews>>.gitignore
echo History>>.gitignore
echo Project Outputs *>>.gitignore
echo * Logs *>>.gitignore

git config --global user.email "r****n@gmail.com"
git config --global user.name "R** F****"

curl -u r***F:p*****d https://api.github.com/user/repos -d "{\"name\":\"%name%\",\"private\":true}"

git init
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:r***F/%name%.git
git push -u origin master

注意:名称显然不包含“*”符号,这只是为了模糊我的细节。

【问题讨论】:

标签: authentication github ssh push


【解决方案1】:

感谢@VonC 的建议

我通过在 push 命令之前添加以下行来让它工作:

git remote set-url origin https://github.com/r****F/%name%.git

不知道为什么,但这有效。所以最终代码的sn-p是:

...
...
git init
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:r****dF/%name%.git
git remote set-url origin https://github.com/r****F/%name%.git
git push -u origin master

【讨论】:

  • 好的,但是完全绕过ssh。
  • 好的,但我不明白如何在我的 github 帐户中访问和创建存储库?
  • 如果您添加了(公共)SSH 密钥并且ssh -Tv git@github.com 有效(意思是,如果它显示欢迎消息),它将能够推送到您的存储库。
【解决方案2】:
git remote add origin git@github.com:r***F/%name%.git

对于测试,您可以检查此语法是否适用于您的情况

git remote add origin ssh://git@github.com/r***F/%name%.git

同时检查一个简单的ssh -Tv git@github.com 是否有效(意思是它是否在最后显示欢迎消息)

【讨论】:

    猜你喜欢
    • 2013-07-08
    • 2022-01-28
    • 2018-02-27
    • 1970-01-01
    • 2015-10-09
    • 2021-09-07
    • 2016-03-18
    • 2015-12-26
    • 1970-01-01
    相关资源
    最近更新 更多