我尝试在 Ubuntu Linux 上使用多个 git 帐户,每当我尝试从第二个帐户推送时,它认为我仍在使用第一个帐户的用户名。
$ git push -u origin master
ERROR: Permission to <act2>/<repo>.git denied to <act1>.
我首先尝试了多个 SSH 密钥方法。 当我收到上述错误时,我在本地计算机上创建了一个全新的用户,以该用户身份登录,重新创建本地存储库(这是第一次推送)并重试。 同样的错误。 我的本地 .config 显示用户,我的 ~/.gitconfig 也是如此。
有什么想法吗?
我愿意: ssh@localhost 然后 ssh -vvv -T 我得到了这个有趣的输出。 它似乎突然消失并在我的帐户中找到了一把钥匙。但不知怎的,它使用了我帐户中的密钥,这确实不应该访问。
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home//.ssh/known_hosts:1
debug2: bits set: 513/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: Wrote 16 bytes for a total of 1015
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1063
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key:
debug2: key:
debug2: key: /home//.ssh/identity ((nil))
debug2: key: /home//.ssh/id_rsa ()
debug2: key: /home//.ssh/id_dsa ((nil))
debug3: Wrote 64 bytes for a total of 1127
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key:
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1495
debug1: Authentications that can continue: publickey
debug1: Offering public key:
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1863
debug1: Remote: Forced command: gerve
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp
debug3: sign_and_send_pubkey
debug3: Wrote 640 bytes for a total of 2503
debug1: Remote: Forced command: gerve
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug3: Wrote 128 bytes for a total of 2631
debug2: callback start
...
ssh-add -l
您可以通过在每个连接的 .ssh/config 中包含 IdentitiesOnly“yes”来强制 ssh-agent 忽略缓存:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_dsa_work
IdentitiesOnly yes
更多信息请访问:
http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/
我也花了很长时间才发现这一点,希望它对某人有帮助。
如果是这种情况,您不应该仅仅为了通过 SSH 以不同的 GitHub 用户身份进行推送而在系统上创建多个用户。 正确的方法是在
github.com
中为
~/.ssh/config
设置两个别名,指定不同的身份文件,如此处所述。 例如,您的
~/.ssh/config
中可能有以下内容:
Host github-act1
HostName github.com
User git
IdentityFile /home/whoever/.ssh/id_rsa.act1
Host github-act2
HostName github.com
User git
IdentityFile /home/whoever/.ssh/id_dsa.act2
然后您可以将两个遥控器添加到您的存储库中:
git add remote act1 git@github-act1:whoever/whatever.git
git add remote act2 git@github-act1:whoever/whatever.git
然后,如果您想作为一个用户进行推送,您可以这样做:
git push act1 master
...或作为第二个帐户:
git push act2 master
ssh github.com -vvvv
确认哪个 SSH 密钥正在传递到 github。
debug2: key:
debug2: key:
debug2: key: /home//.ssh/identity ((nil))
debug2: key: /home//.ssh/id_rsa ()
debug2: key: /home//.ssh/id_dsa ((nil))
这看起来非常可疑。为什么你的主目录只是
/home/
?如果多个用户具有相同的主目录,那么 ssh 为两个用户找到相同的密钥我并不感到惊讶。检查结果
echo $HOME
以每个用户身份登录时。他们应该指向不同的目录。