After searching a lot on the web and with the community help I figured out how to configure 2 differents bitbuckets account on my Mac - MacOS Monterey.
Suppose that you have 2 bitbucket accounts witch usernames are username1 and username12.
- Open the terminal and create 2 ssh file2 for both usernames:
ssh-keygen -f ~/.ssh/username1-Bitbucket
ssh-keygen -f ~/.ssh/username2-Bitbucket
- Start ssh-agent:
eval $(ssh-agent)
- Create or edit the ~/.ssh/config file:
Create:
touch ~/.ssh/config
open ~/.ssh/config
Edit:
open ~/.ssh/config
The ~/.ssh/config file should look like this:
Host username1-Bitbucket
HostName bitbucket.org
User username1
IdentityFile ~/.ssh/username1-Bitbucket
Host username2-Bitbucket
HostName bitbucket.org
User username2
IdentityFile ~/.ssh/username2-Bitbucket
Host *
UseKeychain yes
AddKeysToAgent yes
PreferredAuthentications publickey
IdentityFile ~/.ssh/username1-Bitbucket
IdentityFile ~/.ssh/username2-Bitbucket
IdentitiesOnly yes
PreferredAuthentications keyboard-interactive,password
- Add the keys to the ssh-agent:
ssh-add --apple-use-keychain ~/.ssh/username1-Bitbucket
ssh-add --apple-use-keychain ~/.ssh/username2-Bitbucket
- Copy the ssh key and add it to your bitbuckets accounts. See link:
pbcopy < ~/.ssh/username1-Bitbucket.pub
pbcopy < ~/.ssh/username1-Bitbucket.pub
- Check if connection to bitbucket succeeded (At least one) in order to add Bitbucket as a known hosts:
ssh -T git@bitbucket.org
Clone your repositories using ssh and cd on the terminal to the repository folder.
Check the reposiroties remote url:
git remote -v
You'll get information like this one:
git@bitbucket.org:companyUserName/repositoryName.git
- Change the repositories remote url:
git remote set-url origin username1@username1-Bitbucket:username1/repositoryName.git
git remote set-url origin username2@username2-Bitbucket:username2/repositoryName.git
So we changed git@bitbucket.org:companyUserName/repositoryName.git
to username1@username1-Bitbucket:username1/repositoryName.git
git
-> username1
or username2
, the username of the accounts.
bitbucket
-> username1-Bitbucket
or username2-Bitbucket
, the host alias of the config file.
companyUserName
-> It's the username of the account that holds the repository, in our case the repositories are owned by username1 or username2.
repositoryName
-> The name of the repository.
- Test your connection on both repositories creating a new branch and trying to push it:
git checkout -b newBranch
git push origin newBranch
If everything works correctly on both repositories, you are done!
Hope that this solution works for every Mac user.
That's all folk!