1

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 "My.CorporateAddress@company.com"    

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:

git@github.com: 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:

git@bitbucket.corporate.companyName.com: 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!

2 Answers2

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 "xxx@yyyy.com" -m PEM -P "" -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C "another@yyyy.com" -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".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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!

Configuring Multiple SSH Keys on Mack