如何正确配置ssh密钥到涉及github和bitbucket的多个远程帐户? [英] How to properly configure ssh keys to multiple remote accounts involving github and bitbucket?
问题描述
我创建并配置了三个本地和远程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(电子邮件Github1是同一个帐户Bitbucket)
ssh-rsa AAAAB3 ... Iq9FkLN6L ricardoramos.usp@gmail.com
$> cat〜/ .ssh / id_rsa_back_track.pub(电子邮件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)
$ b 配置〜/ .ssh /配置文件
#默认Bitbucket - 用户= ricardoramos
主机bitbucket.org
HostName bitbucket.org
用户git
IdentityFile〜/ .ssh / id_rsa
#Account GitHub1 - User = ricardousp
Host github.com
HostName github.com
User git
IdentityFile〜/ .ssh / id_rsa_git_hub
#帐户GitHub2 - 用户= ricardormoliveira
主机github.com
主机名github.com
用户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
错误:ricardormoliveira / testing.git被拒绝给ricardousp。
致命:无法从远程存储库读取。
请确保您拥有正确的访问权限
并存在存储库。
如何使用我的ricardormoliveira用户执行git push操作,而不是ricardousp用户?为什么git正在改变我的用户?我在做什么错了?
我的解决方案是:
我的帐户:
$ b Bitbucket
用户名:ricardoramos -
电子邮箱:ricardoramos.usp@gmail.com
Github - 01
搜寻:ricardousp
电子邮箱:ricardoramos@icmc.usp.br
Github - 02
搜寻:ricardormoliveira <
电子邮件:ricardo.comp.ufla@gmail.com
对于执行以下步骤的每个帐户:
-
ssh-keygen -t rsa -Cmy email
-
ssh-add〜/ .ssh /(没有.pub的密钥名称)
- 键未运行命令
ssh-add -D
,因为我
认为这个命令只擦掉了chache,实际上这是
是我的错! -
ssh-add -l </ code>
- 转到目录
〜 /.ssh
- 如果没有配置文件,只需在目录
〜/ .ssh code>
-
sudo nano config
- 在配置文件中添加以下设置存档ssh文件夹
我的最终ssh配置文件:
#Default Bitbucket电子邮件:ricardoramos.usp@gmail.com
主机bitbucket.org-ricardoramos
主机名bitbucket.org
用户git
IdentityFile〜/ .ssh / id_rsa
#Account GitHub1电子邮件:ricardoramos@icmc.usp.br
主机github.com-ricardousp
HostName github.com
User git
IdentityFile〜/ .ssh / id_rsa_github
#Account GitHub2电子邮件:ricardo.comp.ufla@gmail.com
主机github.com-ricardormoliveira
HostName github.com
User git
IdentityFile〜/ .ssh / id_rsa_sec
完成创建和配置所有密钥后,只需设置远程存储库:
-
cat〜/ .ssh / id_rsa.pub
- 复制我的密钥
ssh-rsa AAAAB3Nz ...我的电子邮件
到剪贴板 - 在bitbucket或github中访问我的配置> SSH密钥添加
key
执行所有步骤后,推送正常工作!
链接这帮助我解决了这个问题:
tutsplus 哈哈哈 I created and configured three ssh keys both locally and remotely as follows: SSH keys - Emails List SSH keys (Two different ssh keys with the same email) Config ~/.ssh/config file In addition, I also created a local repository with the name test and remote configuration: But, when I try to push with my ricardormoliveira remote user the following message appears: How do I do that git push with my ricardormoliveira user and not for ricardousp user? Why git is changing my users? What am I doing wrong? My solution was: My accounts: Bitbucket Github – 01 Github – 02 For each of the accounts performed the following steps: My final ssh configuration file: After you finish creating and configuring all the keys just set the remote repositories: After performing all the steps the push worked normally! Link that helped me solve the problem: tutsplus If I do not forget anything you think that's it! Hahaha 这篇关于如何正确配置ssh密钥到涉及github和bitbucket的多个远程帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
youtube
stackoverflow
$> 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-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)
#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
$> git remote -v
origin git@github.com:ricardormoliveira/testing.git (fetch)
origin git@github.com:ricardormoliveira/testing.git (push)
$> 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.
Usuário: ricardoramos
E-mail: ricardoramos.usp@gmail.com
Usuário: ricardousp
E-mail: ricardoramos@icmc.usp.br
Usuário: ricardormoliveira
E-mail: ricardo.comp.ufla@gmail.com
ssh-keygen -t rsa -C "my email"
ssh-add ~/.ssh/(key name without the .pub)
ssh-add -D
, because I
thought that this command only wipe the chache and in fact this was
being my mistake!ssh-add -l
~/.ssh
~/.ssh
sudo nano config
#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
to clipboard
youtube
stackoverflow