'How can I add multiple SSH keys for a Github account and a Bitbucket corporate account
I have two different accounts where I have to upload changes to, the thing here is that the GitHub account and the Bitbucket account has different email addresses, so I'm trying to configure multiple ssh keys in order to keep committing, pushing and pulling changes from Github and Bitbucket respectively.
I've tried to generate two different ssh-keys by running:
ssh-keygen -t rsa -C "[email protected]"
Then, when asked to enter the file in which to save the key I add this:
Enter file in which to save the key (/Users/myUser/.ssh/id_rsa): /Users/myUser/.ssh/id_rsa_github
I do the same steps with the bitbucket one.
Then I generate a file named config and edit it by adding:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
Host bitbucket
HostName corporate-address.com
User git
IdentityFile ~/.ssh/id_rsa_bitbucket
But when I run:
ssh -T git@bitbucket
Or:
ssh -T git@github
And try to make a pull request for any of those, I get the following error:
GITHUB ERROR:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
---------------------------------------------------
---------------------------------------------------
BITBUCKET ERROR:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
For security reasons, I omitted the company name.
What I'm trying to achieve is the possibility to work with both, my work Bitbucket account and my Personal Github account which are configured with a different email address.
What am I doing wrong? Your feedback will be truly appreciated it!
Solution 1:[1]
To test your different key, you should type:
ssh -Tv github
ssh -Tv bitbucket
No need to add the user.
Try again, with the old PEM format
ssh-keygen -t rsa -C "[email protected]" -m PEM -P "" -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C "[email protected]" -m PEM -P "" -f ~/.ssh/id_rsa_bitbucket
But make sure to add your public keys to your accounts.
Example for GitHub: "Adding a new SSH key to your GitHub account".
Solution 2:[2]
I was finally able to configure my two git accounts, they're now up and running.
I followed this tutorial I found and it worked like charm!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | VonC |
| Solution 2 | Manu De Quevedo |
