我最近遇到了一个问题,我无法将更改推送到我已经克隆下来的存储库作为我在桌面上使用git推送的第一个用户中的另一个用户。
基本上它是这样的,
我终于能够使用以下内容推送我的更改:
GIT_SSH_COMMAND="ssh -i <path to private ssh key for second user>" git push
我正在为经历过这个问题的其他人发帖,并提出几个问题,
因此,目标是将更改推送到多个github帐户,而无需执行临时指定要使用的ssh密钥之类的操作。
https://github.com/schwaggs/testssh
https://github.com/jjschweigert/testrepo
[email protected]:schwaggs / testssh.git
[email protected]:jjschweigert / testrepo.git
$ cat ~/.ssh/config
Host jjschweigert
HostName github.com
User git
IdentityFile ~/.ssh/jjschweigert_key
Host schwaggs
HostName github.com
User git
IdentityFile ~/.ssh/jjschweigert_key
$ git clone jjschweigert:jjschweigert/testrepo.git
Cloning into 'testrepo'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 28 (delta 0), reused 28 (delta 0), pack-reused 0
Receiving objects: 100% (28/28), done.
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 261 bytes | 43.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To jjschweigert:jjschweigert/testrepo.git
c082e38..31b7830 master -> master
$ git clone schwaggs:schwaggs/testssh.git
Cloning into 'testssh'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 21 (delta 0), reused 18 (delta 0), pack-reused 0
Receiving objects: 100% (21/21), done.
$ git push
ERROR: Permission to schwaggs/testssh.git denied to jjschweigert.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ ssh -T jjschweigert
Hi jjschweigert! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T schwaggs
Hi jjschweigert! You've successfully authenticated, but GitHub does not provide shell access.
清除Windows凭据管理器中的git条目无法解决此问题。
如果您使用的是ssh URL([email protected]:<user>/<repo>
),则不涉及凭证管理器:它仅为https://
URL提供凭据。
首次使用git,在推送到存储库时会询问github凭据。
仅当远程源URL是https URL时才会出现这种情况。
因此,目标是将更改推送到多个github帐户,而无需执行临时指定要使用的ssh密钥之类的操作。
这是通过ssh配置文件完成的:参见实例:
从编辑
How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?
如果user2条目的SSH配置引用user1私钥,则不能指望push为user2。
根据与VonC的对话,您可以在ssh配置文件中清楚地看到第二个用户的身份文件不正确,因为它指向第一个用户文件。第二个条目从第一个条目复制而且此值未更改。
修改值以指向正确的键,即〜/ .ssh / schwaggs_key后,我可以克隆并推送没有问题。作为旁注,我必须在git中为每个用户提取的每个存储库设置用户的电子邮件和名称属性,即一次在回购中,
How to set up authentication for two separate GitHub accounts from same ssh client?