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.