How to Connect Multiple Bitbucket Accounts in Ubuntu

How to Connect Multiple Bitbucket Accounts in Ubuntu

Are you juggling between different Bitbucket accounts and struggling to streamline the process on your Ubuntu machine? Let’s simplify it. Follow these steps to generate SSH keys, configure SSH for multiple Bitbucket accounts, and make your Ubuntu environment a hub for efficient Bitbucket collaboration.

1. Generate SSH Keys for Each Bitbucket Account

1.1 Open a terminal on your Ubuntu machine.

1.2 Create the first SSH key pair for the primary Bitbucket account

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa

Follow the on-screen instructions, and you can press Enter to accept the default file location.

1.3 Create the second SSH key pair for the secondary Bitbucket account

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_2

Again, follow the on-screen instructions.

2. Configure SSH for Multiple Bitbucket Accounts

2.1 Open or create the SSH configuration file

nano ~/.ssh/config

2.2 Add the following configuration for the first Bitbucket account

Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
User git
IdentitiesOnly yes

2.3 Add the configuration for the second Bitbucket account

Host bitbucket.org2
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_2
User git
IdentitiesOnly ye

Save the changes and exit the text editor.

3. Verify SSH Configuration

3.1 Test the first Bitbucket account connection

ssh -vT bitbucket.org

Ensure that the connection is successful.

3.2 Test the second Bitbucket account connection

ssh -vT bitbucket.org2

Verify that the connection is successful as well.

4. Change Existing Local Project URL Host

4.1 Navigate to your local project directory

cd /path/to/your/local/project

4.2 Edit the Git configuration file

nano .git/config

4.3 Locate the remote URL section, and update the URL for the Bitbucket repository. For example

[remote "origin"]
    url = [email protected]:username/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Save the changes and exit the text editor.

Now, your Ubuntu machine is set up to connect to multiple Bitbucket accounts using different SSH keys, and your existing local projects are configured to use the correct Bitbucket account URLs.

Thank you for exploring FastDT. Explore our range of services to enhance your business.

Learn more about our services