Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup multiple SSH keys

Irakli Ghachava October 21, 2024 edited

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
I can't connect to either bitbucket.org-{username_1} or bitbucket.org-{username_2}.
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.

1 answer

1 accepted

1 vote
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 22, 2024

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 bitbucket.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 for bitbucket.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

Irakli Ghachava October 24, 2024

@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

Screenshot 2024-10-25 at 00.12.58.png Screenshot 2024-10-25 at 00.12.52.png Screenshot 2024-10-25 at 00.14.16.png Screenshot 2024-10-25 at 00.14.35.png

Irakli Ghachava October 24, 2024

This is why I get when I run 

ssh -Tvvv git@bitbucket.org-{username1}

Screenshot 2024-10-25 at 00.18.02.png

Irakli Ghachava October 24, 2024 edited

I've deleted /etc/ssh and it still doesn't work

Screenshot 2024-10-25 at 00.27.26.png

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 29, 2024

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:

  • SSH config: Host entry set as bitbucket.org-key1
Host bitbucket.org-key1
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket-nari
  • Git remote URL : The URL needs to match the Host entry of the config file (bitbucket.org-key1)
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

Irakli Ghachava November 27, 2024

Hi @Patrik S .

What you've suggested works!

 

Thank you!

Like • Patrik S likes this
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 27, 2024

Awesome @Irakli Ghachava ! Glad I could be of some help :)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events