【发布时间】:2022-03-18 08:18:52
【问题描述】:
我在本地和远程创建并配置了三个 ssh 密钥,如下所示:
SSH 密钥 - 电子邮件
$> cat ~/.ssh/id_rsa.pub (E-mail Bitbucket)
ssh-rsa AAAAB3.../kJVKej/5 ricardoramos.usp@gmail.com
$> cat ~/.ssh/id_rsa_git_hub.pub (E-mail Github1 is the same account Bitbucket)
ssh-rsa AAAAB3...Iq9FkLN6L ricardoramos.usp@gmail.com
$> cat ~/.ssh/id_rsa_back_track.pub (E-mail Github2)
ssh-rsa AAAAB3N...MSdYFaZ0d ricardo.comp.ufla@gmail.com
列出 SSH 密钥(同一电子邮件的两个不同 ssh 密钥)
$> ssh-add -l
2048 6b:0b:dd...e6:b7 ricardoramos.usp@gmail.com (RSA)
2048 fc:20:37...1a:ec ricardo.comp.ufla@gmail.com (RSA)
2048 45:4c:92...40:70 ricardoramos.usp@gmail.com (RSA)
配置 ~/.ssh/config 文件
#Default Bitbucket - User = ricardoramos
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
#Account GitHub1 - User = ricardousp
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_git_hub
#Account GitHub2 - User = ricardormoliveira
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_back_track
此外,我还创建了一个名为 test 和远程配置的本地存储库:
$> git remote -v
origin git@github.com:ricardormoliveira/testing.git (fetch)
origin git@github.com:ricardormoliveira/testing.git (push)
但是,当我尝试使用我的 ricardormoliveira 远程用户推送时,会出现以下消息:
$> git push origin master
ERROR: Permission to ricardormoliveira/testing.git denied to ricardousp.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我如何使用我的 ricardormoliveira 用户而不是 ricardousp 用户执行 git push?为什么 git 会改变我的用户?我做错了什么?
【问题讨论】:
-
您是否将 pub 密钥添加到您的 github 个人资料中?
-
github 和 bitbucket 都提供 ssh 进行调试。首先尝试使用
-vvv标志。 -
你好@steveax,就像我使用这个 -vvv 标志一样?你能帮帮我吗?
-
github instructions,bitbucket 也有说明:confluence.atlassian.com/bitbucket/…