如何正确配置ssh密钥到涉及github和bitbucket的多个远程帐户? [英] How to properly configure ssh keys to multiple remote accounts involving github and bitbucket?

查看:140
本文介绍了如何正确配置ssh密钥到涉及github和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



对于执行以下步骤的每个帐户:


  1. ssh-keygen -t rsa -Cmy email

  2. ssh-add〜/ .ssh /(没有.pub的密钥名称)

  3. 键未运行命令 ssh-add -D ,因为我
    认为这个命令只擦掉了chache,实际上这是
    是我的错!

  4. ssh-add -l <​​/ code>

  5. 转到目录〜 /.ssh

  6. 如果没有配置文件,只需在目录
    〜/ .ssh code>

  7. sudo nano config

  8. 在配置文件中添加以下设置存档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

完成创建和配置所有密钥后,只需设置远程存储库:


  1. cat〜/ .ssh / id_rsa.pub

  2. 复制我的密钥 ssh-rsa AAAAB3Nz ...我的电子邮件到剪贴板

  3. 在bitbucket或github中访问我的配置> SSH密钥添加
    key

执行所有步骤后,推送正常工作!

链接这帮助我解决了这个问题:

tutsplus

youtube

stackoverflow

哈哈哈


I created and configured three ssh keys both locally and remotely as follows:

SSH keys - Emails

$> 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

List SSH keys (Two different ssh keys with the same email)

$> 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)

Config ~/.ssh/config file

#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

In addition, I also created a local repository with the name test and remote configuration:

$> git remote -v

origin  git@github.com:ricardormoliveira/testing.git (fetch)
origin  git@github.com:ricardormoliveira/testing.git (push)

But, when I try to push with my ricardormoliveira remote user the following message appears:

$> 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.

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
Usuário: ricardoramos
E-mail: ricardoramos.usp@gmail.com

Github – 01
Usuário: ricardousp
E-mail: ricardoramos@icmc.usp.br

Github – 02
Usuário: ricardormoliveira
E-mail: ricardo.comp.ufla@gmail.com

For each of the accounts performed the following steps:

  1. ssh-keygen -t rsa -C "my email"
  2. ssh-add ~/.ssh/(key name without the .pub)
  3. After the key does not run the command ssh-add -D, because I thought that this command only wipe the chache and in fact this was being my mistake!
  4. ssh-add -l
  5. go to the directory ~/.ssh
  6. if there is no config file, simply create it in the directory ~/.ssh
  7. sudo nano config
  8. add the following settings in the config file the ssh folder

My final ssh configuration file:

#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

After you finish creating and configuring all the keys just set the remote repositories:

  1. cat ~/.ssh/id_rsa.pub
  2. copy my key ssh-rsa AAAAB3Nz... my email to clipboard
  3. in bitbucket or github access my configuration > SSH keys add the key

After performing all the steps the push worked normally!

Link that helped me solve the problem:

tutsplus
youtube
stackoverflow

If I do not forget anything you think that's it! Hahaha

这篇关于如何正确配置ssh密钥到涉及github和bitbucket的多个远程帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆