如何在同一个系统中使用多个ssh密钥维护多个bitbucket帐户 [英] How to maintain multiple bitbucket accounts with multiple ssh keys in the same system

查看:146
本文介绍了如何在同一个系统中使用多个ssh密钥维护多个bitbucket帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个Git帐户,一个是我个人使用的,一个是公司使用的。这两个帐户源都需要从我的笔记本电脑启动。
在这里,我生成了两个ssh键,如id_rsa.pub,id_benwork_rsa.pub
,并且我将 config 配置为

 主机sfsworkdid 
主机名bitbucket.org
IdentityFile〜/ .ssh / id_rsa
主机工作单元
HostName bitbucket.org
IdentityFile〜/ .ssh / id_benwork_rsa

是:: - ,同时推送任何回购git询问第一个ssh_key密码。
每当我将git config中的user.name改为 git config user.namemybitbucketusername
所以请指定我如何在同一个系统中使用多个ssh密钥维护多个git帐户。


我用



确保ssh-agent正在运行并加载您的密钥



,它适用于我!


I have multiple Git accounts one is my personal use and one is of company use. Both accounts source need to be activated from my laptop. Here I generated two ssh keys like id_rsa.pub,id_benwork_rsa.pub and I configured the config of git as

Host sfsworkdid
 HostName bitbucket.org
 IdentityFile ~/.ssh/id_rsa
Host workdid
 HostName bitbucket.org
 IdentityFile ~/.ssh/id_benwork_rsa

so here my problem is::- while pushing to any repo git asking the first ssh_key passphrase. Everytime I am changing the user.name in git config as git config user.name "mybitbucketusername". So Please specify me how to maintain multiple git accounts with multiple ssh keys in the same system

I gone with How to work with multiple ssh keys, Multiple bitbucket accounts but no use Blockquote

push using multiple account / multiple identity on github / bitbucket is somewhat helpful to reach upto now

解决方案

Create multiple identities for Mac OSX, GitBash, and Linux

You should at this point already have created at least a single default identity. To see if you have a default identity already, list the contents of your .ssh directory. Default identity files appear as a id_encrypt and id_encrypt.pub pair. The encrypt value is either rsa or dsa. Use the ssh-keygen command to create a new identity. In the example below, the identity is named personalid.

$ ssh-keygen -f ~/.ssh/personalid -C "personalid"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/manthony/.ssh/personalid.
Your public key has been saved in /Users/manthony/.ssh/personalid.pub.
The key fingerprint is:
7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 personalid
The key's randomart image is:
+--[ RSA 2048]----+
|         |
|         |
|        .|
|        Eo|
|  .  S  . ..|
|  . . o . ... .|
|  . = = ..o o |
|  . o X ... . .|
|  .ooB.o ..  |
+-----------------+

If you have multiple Bitbucket accounts, you need to generate a new public/private key pair for each account.

Create a SSH config file

When you have multiple identity files, create a SSH config file mechanisms to create aliases for your various identities. You can construct a SSH config file using many parameters and different approaches. The format for the alias entries use in this example is:

Host alias
HostName bitbucket.org
IdentityFile ~/.ssh/identity

To create a config file for two identities (workid and personalid), you would do the following:

  1. Open a terminal window.
  2. Edit the ~/.ssh/config file. If you don't have a config file, create one.
  3. Add an alias for each identity combination for example:

    Host workid
     HostName bitbucket.org
     IdentityFile ~/.ssh/workid
    Host personalid
     HostName bitbucket.org
     IdentityFile ~/.ssh/personalid
    

  4. Close and save the file.

Now, you can substitute the alias for portions of the repository URL address as below: git@bitbucket.org:accountname/reponame.git -> git@alias:accountname/reponame.git

Load each key into the appropriate Bitbucket account

Ensure the ssh-agent is running and loaded with your keys

Clone a repository using SSH and your alias configuration

To clone a repository with one of multiple SSH identities that you configured, you clone the repo and using your alias in the SSH URL. To try this for yourself, log into Bitbucket and do the following:

  1. Navigate to the repository Overview.
  2. Display the SSH URL.
    For example, ssh URL as:
    git@bitbucket.org:accountname/reponame.git
    then clone the repository using:
    git clone git@personalid:accountname/reponame.git

This refers to official solution Configure multiple SSH identities for GitBash, Mac OSX, & Linux, It works fine for me!

这篇关于如何在同一个系统中使用多个ssh密钥维护多个bitbucket帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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