Multiple bitbucket accounts

后端 未结 5 547
滥情空心
滥情空心 2021-01-29 19:12

I have a Bitbucket account for my 9-5 job and I also have a personal Bitbucket account. My goal is to be able to use both on the same computer. I have installed the latest git o

5条回答
  •  情歌与酒
    2021-01-29 19:47

    This blog post describes a straightforward way to add multiple ssh keys to a single computer and use one ssh key per a bitbucket account. It is much clearer than the official bitbucket documentation. To summarize:

    First, make sure you have a default account setup through a tutorial like this one on Github.

    For the second account:

    1. Create a new ssh key:

      ssh-keygen -f ~/.ssh/ -C ""
      
    2. Add the ssh key:

      ssh-add ~/.ssh/ 
      
    3. Use pbcopy < ~/.ssh/.pub to copy the public key and add this key to your bitbucket account (in the settings area)

    (On Windows you can copy the ssh key using ssh-keygen -f ~/.ssh/ -c "" | clip or on Linux you can follow these instructions.)

    1. Add the following to your ~/.ssh/config file. The first sets the default key for bitbucket.org. The second sets your second key to an alias bitbucket-account2 for bitbucket.org:

      Host bitbucket.org
        Hostname bitbucket.org
        IdentityFile ~/.ssh/id_rsa
      
      Host bitbucket-account2
        Hostname bitbucket.org
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/
      
    2. You can now clone projects with your default account the same way as before:

      git clone git@bitbucket.org:username/project.git
      
    3. To clone a project with the second identity, replace bitbucket.org with the Host that you specified in the ~/.ssh/config file (i.e. bitbucket-account2 above):

      git clone git@bitbucket-account2:username/project.git
      

    That's it!

提交回复
热议问题