It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add bitbucket's public key to my known_hosts file?

I have a server that needs to run the command "git ls-remote" against one of my bitbucket Git repositories to locate a branch's commit hash.  I think I need to add bitbucket's public key to my .ssh/known_hosts file on my server in order to avoid the dreaded prompt, "The authenticity of 'bitbucket.org (ip6) can't be established."  However, I need to run this command inside a script.  How can I fetch that key inside my script and then write it to the known_hosts file?  I think I'm supposed to use the command "ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts" but when I run that command I get some extra lines that don't look like they belong in my known_hosts file:

       # bitbucket.org:22 SSH-2.0-conker... app-133           <- Don't want this line

       # bitbucket.org:22 SSH-2.0-conker... app-126           <- Don't want this line

       bitbucket.org ssh-rsa AAAAB3N...                               <- Just need this line?

      # bitbucket.org:22 SSH-2.0-conker... app-132            <- Don't want this line

I think all I want is the third line above.  Is there a command to just pull that piece of data out so I can append it to my known_hosts file?  Thanks.

2 answers

0 votes

Hi! 

As I understand your problem mostly related IPv6, 

Please, have a look that answer 

https://stackoverflow.com/questions/42888832/cant-push-pull-to-bitbucket-via-ssh-using-ipv6

Host bitbucket
     HostName bitbucket.org
     User git
     IdentityFile ~/.ssh/id_rsa_bitbucket
     AddressFamily inet

 

I hope that info will help for you. 

 

 

Cheers,

Gonchik Tsymzhitov

Thanks Gonchik.  But I don't see how this is related to ipv6.  I'm just trying to figure out how to discover a bitbucket public RSA key programmatically so that I can insert it in my known_hosts file.  Perhaps bb posts it somewhere and I can just copy it into the file and push the file to my server.

I elected to create an SSH config file that turns off strict host key checking for my trusted host:

Host my-trusted-host.com
  StrictHostKeyChecking no

I know this is not the best solution but it is a temporary fix.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

4,081 views 4 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you