Bitbucket different keys and accounts

Any way of configuring ssh to use a different key for each account of bitbucket (or github)?

I mean, if I’m going to work with *.bitbucket:user1 ssh should use key id_rsa.user1 and for *.bitbucket:user2 should user id_rsa.user2

  • Will changing my Github username to SnakeCase break anything?
  • How to safely change github account name?
  • PhpStorm. Two GitHub projects handled with different GitHub accounts
  • Github wrong username
  • Github - I switched accounts and now I can't push because I have the wrong username
  • GitHub username change (with noreply as email for commits)
  • Have tried it by doing:

    IdentityFile ~/.ssh/id_rsa.user1
    IdentityFile ~/.ssh/id_rsa.user2
    
    Host *.bitbucket.org:user1*
      IdentityFile ~/.ssh/id_rsa.user1
      User git
    
    Host *.bitbucket.org:user2*
      IdentityFile ~/.ssh/id_rsa.user2
      User git
    

    But no luck.

  • How to linearize “splintered” merging history in Git?
  • feasibility of git without a remote repo
  • Adding gitignore after multiple commits
  • Copy and move a file in git?
  • GIT: How can I prevent foxtrot merges in my 'master' branch?
  • Simple Github commit not working (trying to add an image to my public image folder)
  • One Solution collect form web for “Bitbucket different keys and accounts”

    With ssh, you can easily name your ssh remote in order to use one set of key or the other, using %HOME%/.ssh/config.
    (this works for BitBucket or GitHub)

    See as an example “change github account mac command line”

    #User 1 on BitBucket
    Host bitbucketu1
      HostName bitbucket.org
      User git
      IdentityFile ~/.ssh/id_rsa.user1
    
    #User 2 on BitBucket
    Host bitbucketu2
      HostName bitbucket.org
      User git
      IdentityFile ~/.ssh/id_rsa.user2
    

    Then, a git clone bitbucketu1:repo1 would clone a repo from user1.

    Git Baby is a git and github fan, let's start git clone.