【问题标题】:"Bad Credentials" when attempting to create a GitHub repo through the CLI using curl尝试使用 curl 通过 CLI 创建 GitHub 存储库时出现“错误的凭据”
【发布时间】:2013-12-07 15:36:35
【问题描述】:

我正在尝试使用命令行创建一个 GitHub 存储库。

建议here可以使用以下命令:

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master

当我使用它时,系统会提示我输入我的密码(我确信这是正确的,因为我可以在 GitHub.com 上成功登录)。然后我收到此错误:

c:\Development\Projects\MovieStar>curl -u 'jonnymaceachern' https://api.github.com/user/repos -d '{"name":"MovieStar"}'
Enter host password for user ''jonnymaceachern'':
{
  "message": "Bad credentials",
  "documentation_url": "http://developer.github.com/v3"
}

我试过在我的用户名周围不加引号,它只是给我一个“解析 JSON 的问题”错误。

【问题讨论】:

    标签: git curl github


    【解决方案1】:

    git@github.com:USER/REPO.git 是 ssh 网址,而不是 https 网址。
    GitHub 询问您的“密码”是因为 ssh 找不到您的公钥/私钥,与您的 GitHub 帐户密码无关。

    用途:

    git remote add origin https://YourName@github.com/YourName/REPO.git
    git push -u master
    

    然后它会询问您的 http 凭据。
    如果您不想为每笔交易输入它,请参阅“Is there a way to skip password typing when using https:// github”。

    【讨论】:

      【解决方案2】:

      我会做什么:

       curl -u 'USER:PASWORD' https://api.github.com/user/repos -d '{"name":"REPO"}'
      

      在我的 github 帐户上测试正常。这样,您将不会被提示输入密码。它不起作用,也许您的密码不是好的密码(或用户名)。

      【讨论】:

      • 仍然遇到同样的错误。甚至登录 GitHub 更改我的密码并重试。在用户名字段中使用我的电子邮件也不起作用。
      • 这会将您的密码保留在您的 shell 历史记录中。 OP的命令在这方面可能更好。
      猜你喜欢
      • 2023-03-13
      • 2021-08-07
      • 2021-07-09
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2015-02-04
      相关资源
      最近更新 更多