Manage Multiple SSH key in one Computer

It's frustate me this morning knowing that I can't pull my own personal repository from bitbucket which saving several of my own library scripts. How's this problem happen? After doing some research, I knew that one ssh-key in a computer must be associated with only one Bitbucket Account, . So, it will be denied when I tried to use the same key into my personal bitbucket account.

conq: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How to fix it? I have to create multiple ssh-key for usage at Bitbucket. Let's try to do it.

  • First, we have to create new ssh-key for each accont. Open Terminal (Mac or Linux) / Git Bash (Windows)
  • Open ssh directory and create two new ssh key, one for work account and one for personal account

    $ cd ~/.ssh/
    $ ssh-keygen

Ssh keygen Ssh keygen2

  • Let's open Bitbucket in web browser. Login to work account, add work ssh-key created before. After you save configuration, logout from it.
  • Repeat same step for personal acccount.
  • Now we have different ssh-key for each account in Bitbucket. Let's try to pull some repository.

Pull access denied

  • Uh oh, It still disabled. Let's check when our ssh key is available in our computer by using command ssh-add.

    $ ssh-add -l

Ssh add list

  • If there is no identities in our computer. We should add our keys manually. We can use command ssh-add to adding our keys. I'll be adding two of mine using ssh-add command.

    $ ssh-add ~/.ssh/work
    $ ssh-add ~/.ssh/personal

  • Last step, you have to create config file at ~/.ssh/ to tell Git which identity will be used in which account.

    Host workid
    IdentityFile ~/.ssh/work
    Host personalid
    IdentityFile ~/.ssh/personal

  • That's it. Now, I can pull and managing reopsitories using different accounts in Bitbucket. This method can be used when using another server.

{{ message }}

{{ 'Comments are closed.' | trans }}