I changed the username and lost access permissions (clone, push)
Asked by Juan Acosta:

Hi, I changed the username of my personal account, following the instructions in the link:

<https://support.atlassian.com/bitbucket-cloud/docs/change-a-workspace-id/>

But both in bitbucket cloud and local repository I lost access to both clone any other repo of my account in my pc and push any local repo from my pc.

When I try to do a push, it opens a login window but my account credentials in the browser (which are correct) throw an error and when I try to clone a repository it shows I don't have access.

I can't generate a new ssh key because it is associated with the bitbucket account of the company where I work.

I appreciate guidance to recover cli access to my account. Thanks!


Answers:
author: Theodora Boudale
body: Hi Juan,

The documentation you linked concerns changing the workspace id of a workspace and not a username. If you change the workspace id of a workspace, the URL of any repo belonging to this workspace is going to change as well. This means that you will need to update the remote URL of your local clone so that it uses the new workspace id. Details are provided in the same documentation, section "Update the URL in your configuration file".

You can use the following command in the directory of your local clone to see its remote URL:

```
git remote -v
```

If you are using SSH, the output will look like

```
origin git@bitbucket.org:<workspace_ID>/<repo_name>.git (fetch)
origin git@bitbucket.org:<workspace_ID>/<repo_name>.git (push)
```

You can change the remote URL of the repo with a command like the following:

```
git remote set-url origin git@bitbucket.org:<workspace_ID-New>/<repo_name>.git
```

where **\<workspace_ID-New\>** replace with the new workspace id  
**origin** replace with the name of your remote, if different

If you have any questions, please feel free to let me know.

Kind regards,  
Theodora

comments: author: Juan Acosta
body: Hi Theodora,

Thanks for the guidance, I changed both the workspace name and the username and I was able to update the remote URL, but to use my personal repository I had to use the ssh key that I had registered in the company's repository. My question is if I'm going to have to keep changing the key between them or is there a better way to use both accounts on my machine. Thanks in advance.


author: Theodora Boudale
body: Hi Juan,

Thank you for the clarification. If I understand correctly, you have two Bitbucket Cloud accounts (personal and work), and you would like to use SSH with both of them from the same machine, is that correct?

In this case, you will need to generate one more SSH key pair, upload the public key of SSH key pair 1 to one account, and then upload the public key of SSH key pair 2 to the other account. You will additionally need to make some configuration changes locally so that the correct key is used for each repo.

The following blog post has step-by-step instructions on how to do that:

* <https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/>

If you have any questions, please feel free to let me know.

Kind regards,  
Theodora


author: Juan Acosta
body: Hi Theodora,

I followed the suggested link and some other guides but I only partially solved the problem.

Only one of the ssh keys registered to my machine is working. This key worked only when I followed the steps and edited the \~/.ssh/config file as the following link shows.

<https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-windows/#Install-OpenSSH-on-Microsoft-Windows>

When in the \~/.ssh/config file I specify the bitbucket user or add any of the other fields, no key works.

I appreciate if you have any other suggestions.

Best regards


author: Theodora Boudale
body: Hi [@Juan Acosta](/t5/user/viewprofilepage/user-id/4863869),

The documentation you linked in your reply will work only for one SSH key because the configuration suggested there is for setting up one key.

<br />

Can you please first confirm if you are indeed using two Bitbucket Cloud accounts and if you have two SSH key pairs on this machine (one for each Bitbucket account)?

If so, please follow all the steps in the documentation I linked earlier:

<https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/>

<br />

Afterwards, I would like to ask if you could please provide the following info, so I can better help you:

**1)** Can you post here the content of your \~/.ssh/config file? Just the parts related to Bitbucket Cloud should be enough.

**2)** Run the clone command with the following arguments for a repo where the clone is failing, and post here the command and full output (you can replace private data like workspace-id and repo slug with dummy values when you post here, but please leave the format the same, so I can check the URL format)

```
GIT_SSH_COMMAND="ssh -vvv" <git command>
```

**3)** Are you using Git Bash on Windows for cloning the repos? Or a different client?

Kind regards,  
Theodora


author: Juan Acosta
body: I [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Thanks for the feedback, I'm using two Bitbucket Cloud accounts, one personal and one for work, This post is from my personal account.

Regarding the indicated guide, I only did two different things after trying a few times:

* generate the ssh key with the following format (both keys but this is the one that doesn't work)

ssh-keygen -t ed25519 -b 4096 -C "user1@email" -f ssh_key_user1

```
ssh-keygen -t ed25519 -b 4096 -C "user1@email" -f ssh_key_user1
```

* Edit the **config** file with the following format

Host bitbucket.org  
AddKeysToAgent yes  
IdentityFile \~/.ssh/ssh_key_user1

Host bitbucket.org  
AddKeysToAgent yes  
IdentityFile \~/.ssh/ssh_key_user2

OBS 1: the key **ssh_key_user1** is working ok!

**R/ 2)** with respect to the indicated command:

GIT_SSH_COMMAND="ssh -vvv" git clone git@bitbucket.org:\<workspace\>/\<repo-name\>.git

The requested repository either does not exist or you do not have access.

**R/ 3)** Yes, I'm using Git Bash on Windows for cloning the repos.

Again, thanks a lot for the help.

Best regards!


author: Juan Acosta
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Just for updated, when I change the order of the keys in the **config** file (all 3 lines), it works, it seems to apply some rule where it only recognizes the first one.


author: Theodora Boudale
body: Hi [@Juan Acosta](/t5/user/viewprofilepage/user-id/4863869) ,

Thank you for sharing the additional info.

The reason that only the first key is recognized is that there are two entries with the same Host, **bitbucket.org**, in your \~/.ssh/config file. Your setup is different than the one in the documentation I linked.

If you don't want to change the order of the keys all the time, you can make the following adjustments:

**1)** In your **\~/.ssh/config**, adjust the entries for Bitbucket Cloud as follows:

```
#user1 account
Host bitbucket.org-user1
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/ssh_key_juan_windows
    IdentitiesOnly yes

#user2 account
Host bitbucket.org-user2
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/ssh_key_juan_if_windows
    IdentitiesOnly yes
```

It is important that each entry has a different value for **Host**, like in the two examples above. Note that each host has one of the two identity files you created.

**2)** ++Configuring the remote URL of your clone++

If you want to clone a repo that the account with the key **ssh_key_juan_windows** can access, please adjust the clone URL as follows:

```
git clone git@bitbucket.org-user1:workspace-a/repo-a.git
```

Please note the part **bitbucket.org-user1** in the URL (instead of bitbucket.org). This is the same as the entry **Host** in the config, so that the clone of this repo will pick up the key **\~/.ssh/ssh_key_juan_windows**.

If you already have a clone of the repo locally, you can adjust the remote URL as follows:

```
git remote set-url origin git@bitbucket.org-user1:workspace-a/repo-a.git
```

Similarly, if you want to clone a repo that your other account can access, the one with the key **ssh_key_juan_if_windows**, you can clone with the URL

```
git clone git@bitbucket.org-user2:workspace-b/repo-b.git
```

Again, note the part **bitbucket.org-user2** in the URL, similar to the Host in the config. This is so that the clone command will pick up the key **ssh_key_juan_if_windows** for this repo.

If you already have a clone of the repo locally, you can adjust the remote URL as follows:

```
git remote set-url origin git@bitbucket.org-user2:workspace-b/repo-b.git
```

If you make these changes, you will no longer need to switch the order of the keys in your \~/.ssh/config. You need to adjust the clone URL every time you clone a new repo, in order to include the appropriate Host in the URL, so that the correct key will be picked up. For existing clones, you can adjust the URLs the way I explained above.

Please feel free to let me know if this works for you and if you need anything further.

Kind regards,  
Theodora


author: Juan Acosta
body: Hi Theodora,

First of all thanks for feedback. but my setup is different because unfortunately the documentation you linked doesn't work for me.

When I add my bitbucket usernames, or the emails used when generating the keys, or just the strings **user1** or **user2** after host bitbucket.org, both keys stop working.

with the following configuration both keys stop working:

```
#user1 account
Host bitbucket.org-user1
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/ssh_key_user1
    IdentitiesOnly yes

#user2 account
Host bitbucket.org-user2
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/ssh_key_user2
    Id
```

I'm really confused about it .

Best regards!


author: Theodora Boudale
body: Hi [@Juan Acosta](/t5/user/viewprofilepage/user-id/4863869),

In the config file, you can use as Host **bitbucket.org-user1** and **bitbucket.org-user2**. You can also replace the strings user1 and user2 with something different instead, like in the example you posted in your last reply.

Changing the SSH config only is not enough though. You will then need to adjust the remote URLs of your existing clones and also use the adjusted URL when you make a new clone. I provided details about that in my last reply, section 2**) Configuring the remote URL of your clone**.

Did you make these adjustments in the remote URL of your local clones, after changing the config?

If you use the config you posted in your last reply, you'll need to replace bitbucket.org-user1 and bitbucket.org-user2 in the URLs with the Hosts you defined in your config.

Kind regards,  
Theodora


author: Juan Acosta
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086),

The combination of both modifications worked, I really appreciate the support received.

Best regards,  
Juan


author: Theodora Boudale
body: Hi Juan,

That's good to hear and thank you for the update! Please feel free to reach out if you ever need anything else.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud