Hi, I've followed the guidelines for setting up multiple SSH keys in bitbucket but it doesn't work.
Here is my setup
~/.ssh/config
Host github.com
IdentityFile ~/.ssh/github
IdentitiesOnly yes
Host bitbucket.org-{username_1}
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket-nari
Host bitbucket.org-{username_2}
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket-delori
ika@Iraklis-MacBook-Pro ~ % ssh -Tv bitbucket.org-{username_2}
OpenSSH_9.8p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/ika/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to bitbucket.org-{username_2} port 22.
ssh: Could not resolve hostname bitbucket.org-{username_2}: nodename nor servname provided, or not known.
Here is local git config in one of my repositories
[user]
name = {username_2}
email = {email}
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@bitbucket.org-{username_2}:trsthb/dpp-portal.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
vscode-merge-base = origin/master
[branch "develop"]
remote = origin
merge = refs/heads/develop
vscode-merge-base = origin/develop
Everytime I run git pull it throws following error
ssh: Could not resolve hostname bitbucket.org-irakli____ghachava: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
What am I doing wrong here?
P.S. Yes, I've added public keys to corresponding bitbucket accounts in personal bitbucket settings.
Hello @Irakli Ghachava ,
thank you for reaching out to the Community!
This happens because the alias you used in your SSH configuration file is not being correctly translated to a valid hostname when you're trying to connect. The alias you define should match exactly what you use in your Git remote URL.
Double-check your SSH config and Git remote URL for any typos. The alias in the SSH config (bitbucket.org-{username_1} and bitbucke
t.org-{username_1}
) should match exactly with what you use in your Git remote URL.
Also, confirm if the owners of the ssh config file is the same user executing the command.
You can check if the configuration is correctly taking place by testing the SSH with more verbose logs :
ssh -Tvvv git@bitbucket.org-{username1}
If the config file is properly configured, we will expect a log similar to below at the very beginning:
debug1: Reading configuration data /Users/<username>/.ssh/config
debug1: /Users/<username>/.ssh/config line 7: Applying options forbitbucket.org-{username_1}
You may also want to check the following guide on how to configure multiple SSH keys in your local environment:
Thank you, @Irakli Ghachava !
Patrik S
@Patrik S thanks for response.
Below you can see 1. my git config 2. remote url in my local git config in repository 3. repo url given by bitbucket by default when cloning 4. my username
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is why I get when I run
ssh -Tvvv git@bitbucket.org-{username1}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Irakli Ghachava ,
the issue is likely due to the underscores you have in the config file.
The appending of your username to the Host entry on the config file is just a suggestion to you can easily identify which account the ssh key that is going to be used was added to. However, you can append any string to the config file, as long as you use the same string in the git remote URL.
For example:
Host bitbucket.org-key1
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket-nari
git@bitbucket.org-key1:WORKSPACE/REPOSITORY.git
Could you change your config file and git remote to match the example above and let us know how it goes?
Thank you, @Irakli Ghachava !
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome @Irakli Ghachava ! Glad I could be of some help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.