我在本地和远程创建和配置了三个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 /配置文件
#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用户进行git push而不是ricardousp用户?为什么git会改变我的用户?我做错了什么?
答案 0 :(得分:1)
你确实认为这是正确的方法。
此处也有描述:Managing two ssh keys
看起来您没有将密钥添加到远程服务器。
https://gist.github.com/jexchan/2351996
create different public key
强> 根据文章Mac Set-Up Git创建不同的ssh密钥
$ ssh-keygen -t rsa -C "your_email@youremail.com"
例如,创建了2个键:
~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
Add these two keys to the ssh-agent:
强> $ ssh-add ~/.ssh/id_rsa_activehacker
$ ssh-add ~/.ssh/id_rsa_jexchan
you can delete all cached keys before
$ ssh-add -D
check your keys
强> $ ssh-add -l
Modify the ssh config
强> $ cd ~/.ssh/
$ touch config
$ subl -a config
Add the keys to the config file:
*** #activehacker account
Host github.com-activehacker
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_activehacker
#jexchan account
Host github.com-jexchan
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_jexchan
Clone you repo and modify your Git config
强> # clone your repo
git clone git@github.com:activehacker/gfs.git gfs_jexchan
cd gfs_jexchan and modify git config
$ git config user.name "jexchan"
$ git config user.email "jexchan@gmail.com"
$ git config user.name "activehacker"
$ git config user.email "jexlab@gmail.com"
# or you can have global
git config $ git config --global user.name "jexchan"
git config --global user.email "jexchan@gmail.com"
push your code
强> git add .
git commit -m "your comments"
git push
答案 1 :(得分:1)
我的解决方案是:
我的帐户:
Bitbucket
Usuário:ricardoramos
电子邮件:ricardoramos.usp@gmail.com
Github - 01
Usuário:ricardousp
电子邮件:ricardoramos@icmc.usp.br
Github - 02
Usuário:ricardormoliveira
电子邮件:ricardo.comp.ufla@gmail.com
对于每个帐户执行以下步骤:
ssh-keygen -t rsa -C "my email"
ssh-add ~/.ssh/(key name without the .pub)
ssh-add -D
,因为我
以为这个命令只擦拭了chache,事实上就是这样
是我的错!ssh-add -l
~/.ssh
~/.ssh
sudo nano config
我的最终ssh配置文件:
#Default Bitbucket email:ricardoramos.usp@gmail.com
Host bitbucket.org-ricardoramos
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
#Account GitHub1 email:ricardoramos@icmc.usp.br
Host github.com-ricardousp
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
#Account GitHub2 email:ricardo.comp.ufla@gmail.com
Host github.com-ricardormoliveira
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_sec
完成创建和配置所有密钥后,只需设置远程存储库:
cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3Nz... my email
复制到剪贴板执行完所有步骤后,推动工作正常!
帮助我解决问题的链接:
tutsplus
youtube
stackoverflow
如果我不忘记任何你认为就是这样的话!哈哈哈