与GIT登记的SSH远程地址可能已经包括用户名,所以你需要使用一个完整的URL的SSH像:
[email protected]:arepo
这是行不通的,因为SSH将使用默认公钥/私钥(当前由第一个用户进行验证)。
您可以在本地配置一个新的远程登记:
# use the current ssh address registered for origin, changing just the user
# but you need a config file
git remote add originOtheruser otheruser:arepo
你必须有一个$HOME/.ssh/config
文件,以定义SSH进入“otheruser”,因为SSH需要知道什么公共/私钥它需要使用:它不能是默认的($HOME/.ssh/id_rsa
和$HOME/.ssh/id_rsa.pub
)
例如,见“how to add deploy key for 2 repo with 1 user on github”
Host otheruser
HostName remote
User otheruser
IdentityFile ~/.ssh/otheruser
那假设你已经存储的公开/私有密钥otheruser为:
$HOME/.ssh/otheruser
$HOME/.ssh/otheruser.pub
现在,您可以使用新的远程推:
git push originOtheruser master
是的,我已经尝试过了。通常我从“git remote -va”复制粘贴。它工作,虽然它创建一个额外的远程追踪分支拉。 – Andor 2013-11-04 14:34:10
我通常使用pubkey来推送提交。即使我指定了一个不同的用户,我仍然会得到'Permission denied(publickey)(公钥)。 致命:无法从远程存储库读取.'如何推送以便我可以输入不同帐户的密码? – nipponese 2017-08-29 03:15:05