2015-07-20 82 views
1

我使用GitHub在文件上存在SSH密钥。我正在尝试将更改推送给其他人的GitHub项目。我有协作者访问该帐户。在推送GitHub期间从命令行使用SSH密钥?

我被提示输入密码:

$ 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://[email protected]': 
remote: Invalid username or password. 
fatal: Authentication failed for 'https://github.com/weidai11/cryptopp.git/' 

GitHub的在Which remote URL should I use?帮助只讨论一个桌面客户端的情况下SSH。我想他们有一个他们希望我使用的应用程序,但我并不想使用它。

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


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

回答

1

要推送另一个帐户,您需要存储在您的~/.ssh文件夹中的其他帐户的私人/公共ssh密钥。

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

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

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 

第二个账户可以通过添加一个新的远程从同一个回购使用:

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

谢谢VonC。有没有办法将GitHub配置为***只使用SSH密钥来访问我的密码?如果GitHub配置正确,那么它不会浪费我的时间与密码提示,我不会做这个客户端(在多台机器上)? – jww

+1

@jww您将配置的是与您本地回购相关的远程URL:键入'git remote -v'来检查那些只是ssh url。并且/或者您可以使用'insteadOf'指令,如http://stackoverflow.com/a/26814985/6309中所述。 – VonC