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 on a Windows 7 pc.
So currently everything with my companies Bitbucket account works fine, I can pull/push with no problems. I created a new ssh key using ssh-keygen and assigned a new name in my case "tech". But I am having issues on how to tell a local repo to use the new ssh key I created. I am assuming everytime I try to connect it uses the first ssh key.
I get the error:
$ git push conq: repository access denied. fatal: The remote end hung up unexpectedly
I found some advice on the internet but it seems to relate to a linux/git setup, for example I can't find the "config" file on windows.
You can now prefix your repository URL with your Bitbucket username to easily use different SSH keys with different accounts. Simply clone from [email protected] and Bitbucket will use the correct key proffered by your SSH agent. (You'll also need to add the contents of ~/. ssh/your-username.
For most developers, there may be a need to run multiple GitHub accounts on one computer. For instance, you can run an Organization's GitHub account and another one for your personal projects all on the same computer. In this article, you will learn how to use multiple SSH keys for different GitHub accounts.
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:
Create a new ssh key:
ssh-keygen -f ~/.ssh/<your second account name> -C "<you email>"
Add the ssh key:
ssh-add ~/.ssh/<key file name>
Use pbcopy < ~/.ssh/<your second account name>.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/<your account name> -c "<your email>" | clip
or on Linux you can follow these instructions.)
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/<your second account name>
You can now clone projects with your default account the same way as before:
git clone [email protected]:username/project.git
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!
You may get this error if you haven't added the key to the key manager (ssh-agent). To do this:
ssh-add ~/.ssh/tech
By the way, if you have multiple Bitbucket accounts, you'll need a unique key for each account. You can't reuse keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With