在GitHub推送期间使用命令行中的SSH密钥吗? [英] Use SSH keys from command line during push for GitHub?

查看:103
本文介绍了在GitHub推送期间使用命令行中的SSH密钥吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitHub上有现有的SSH密钥.我正在尝试将更改推送到其他人的GitHub项目.我具有对该帐户的合作者访问权限.

I have existing SSH keys on file with GitHub. I'm trying to push a change to someone else's GitHub project. I have Collaborator access to the account.

系统提示我输入密码:

$ 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的帮助,位于我应该使用哪个远程URL? 仅在桌面客户端的上下文中讨论SSH.我猜他们有一个要我使用的应用程序,但我真的不想使用.

GitHub's help at Which remote URL should I use? only discusses SSH in the context of a Desktop client. I guess they have an app they want me to use, but I don't really want to use one.

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

How do I have the command line tool use my SSH keys for pushing changes to a GitHub account?

这与与我如何作为协作者从命令行签出GitHub项目相关?.我以前无法以协作者身份使用凭据进行结帐,现在却陷入了此密码身份验证陷阱.

This is related to How do I checkout a GitHub project from command line as a Collaborator?. I was never able to checkout with credentials as a collaborator, and now I fall into this password authentication trap.

推荐答案

要推送为另一个帐户,您需要存储在~/.ssh文件夹中的该另一个帐户的私钥/公用ssh密钥.

To push as another account, you would need the private/public ssh keys from that other account stored in your ~/.ssh folder.

您还需要类似于以下内容的ssh配置文件(~/.ssh/config)

You would also need an ssh config file (~/.ssh/config) similar to:

声明多个密钥的ssh配置文件:

ssh config file declaring multiple keys:

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

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

您将使用ssh url之类的

And you would use ssh url like

githubUserA:userA/myrepo1
githubUserB:userB/myrepo2

可以通过添加新的远程服务器,从同一存储库中使用第二个帐户:

The second account could be used from the same repo by adding a new remote:

git remote add guserB githubUserB:userB/myrepo2
git push gUserB myBranch

这篇关于在GitHub推送期间使用命令行中的SSH密钥吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆