我在 GitHub 上存档了现有的 SSH key 。我正在尝试将更改推送到其他人的 GitHub 项目。我拥有该帐户的协作者访问权限。

系统提示我输入密码:

$ git push 
warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 
 
  git config --global push.default matching 
 
To squelch this message and adopt the new behavior now, use: 
 
  git config --global push.default simple 
 
When push.default is set to 'matching', git will push local branches 
to the remote branches that already exist with the same name. 
 
In Git 2.0, Git will default to the more conservative 'simple' 
behavior, which only pushes the current branch to the corresponding 
remote branch that 'git pull' uses to update the current branch. 
 
See 'git help config' and search for 'push.default' for further information. 
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 
'current' instead of 'simple' if you sometimes use older versions of Git) 
 
Username for 'https://github.com': xxxxxx 
Password for 'https://xxxxxx@github.com':  
remote: Invalid username or password. 
fatal: Authentication failed for 'https://github.com/weidai11/cryptopp.git/' 

GitHub 的帮助位于 Which remote URL should I use?仅在桌面客户端的上下文中讨论 SSH。我猜他们有一个他们想让我使用的应用程序,但我真的不想使用一个。

如何让命令行工具使用我的 SSH key 将更改推送到 GitHub 帐户?

这与 How do I checkout a GitHub project from command line as a Collaborator? 有关.作为合作者,我永远无法使用凭据结帐,现在我陷入了这个密码验证陷阱。

请您参考如下方法:

要作为另一个帐户推送,您需要存储在您的 ~/.ssh 中的另一个帐户的私有(private)/公共(public) ssh key 。文件夹。

您还需要一个 ssh 配置文件 (~/.ssh/config),类似于:

ssh 配置文件声明多个 key :

Host githubUserA 
    Hostname github.com 
    IdentityFile ~/.ssh/id_rsa 
    User git 
 
Host githubUseB 
    Hostname github.com 
    IdentityFile ~/.ssh/other 
    User git 

你会使用 ssh url 像
githubUserA:userA/myrepo1 
githubUserB:userB/myrepo2 

通过添加一个新的 Remote ,可以从同一个 repo 中使用第二个帐户:
git remote add guserB githubUserB:userB/myrepo2 
git push gUserB myBranch 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!