Bitbucket Pipeline Host key verification failed. (Centos)

Nishantha Kumara January 8, 2021

I'll try to set up the bitbucket pipeline for my deployments. I'll add the pipeline to the bitbucket repository and configure the SSH keys correctly with Known hosts. after that, I'll run the ssh commands every time getting Host key verification failed This is my pipeline configuration

 

image: php:7.2
pipelines:
default:
- step:
name: "Logging to server"
script:
- apt-get update && apt-get install -y unzip
- apt-get install -y openssh-client
- echo "Trying to logging ..."
- ssh root@ip

And I already added the generated(from bitbucket ssh section) public key to my server's  ~/.ssh/authorized_keys file. How can fix the issue.? (centos 7 server)

 

Pseudo-terminal will not be allocated because stdin is not a terminal.Host key verification failed.

When I run 

ssh-keyscan -t rsa bitbucket.org
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAAB ...

Thanks.

2 answers

0 votes
Kevin May 30, 2022

1. go to -> Repository settings

2. go to -> SSH keys ( on the left navigation)

3. at the known hosts section

- input your Bastion host public IP address

- then click Fetch button

- rerun your pipeline

Please check this thread. https://community.atlassian.com/t5/Bitbucket-questions/read-passphrase-can-t-open-dev-tty-No-such-device-or-address/qaq-p/1774842

riadb September 1, 2023

This saved me a ton of time! Thank you!

0 votes
Dave Gilmore January 11, 2021
Hi,

I faced a similar issue, when creating immutable infrastructure as part of my Pipeline.

I used the following to mitigate:

- terraform apply
-auto-approve

-
ec2_public_ip=$(terraform output -json | jq -r '.public_dns.value')
-
echo $ec2_public_ip
-
ssh-keyscan -t rsa $ec2_public_ip >> ~/.ssh/known_hosts
-
pipe: atlassian/ssh-run:0.2.8
variables: SSH_USER: 'fedora'
SERVER: $ec2_public_ip
COMMAND: 'curl ifconfig.me'
 
You could also create a step, that outputs a fingerprint artifact:

- step: &get-fingerprint name: Get Host Fingerprint to add to known_hosts script:
-
ssh-keyscan -t rsa $ec2_public_ip > fingerprint
artifacts:
-
fingerprint

Nishantha Kumara January 11, 2021

Thanks. but it's not working. still getting below issue. 

ssh -A -tt -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 root@ip php -v 

Permission denied, please try again.Permission denied, please try again.root@ip: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

Dave Gilmore January 11, 2021

Are you able to run a quick test step?

`ssh -T root@ip'

Also, are you sure you want to connect with root ?

Nishantha Kumara January 11, 2021

actually, I don't need to run with the root. but several times getting permission issues  know, that's why ill try with the root. 

ssh -T root@ip

 

getting same error

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)

Dave Gilmore January 11, 2021

Yes, but using an incorrect user can also cause this same issue.

i.e. if I was to try and connect to an AWS ec2 instance and I don't use the centos username I would get permission denied or at least a message saying to login with centos

I have this working no problems, my key is defined in Pipelines -> SSH Keys and this is the same Key I use to launch my instances.

I use the fingerprint method described above to add the host to known_hosts on the fly.

So either:

The user is incorrect

or 

The Key is incorrect.

Like Nishantha Kumara likes this
Nishantha Kumara January 11, 2021

Thanks @Dave Gilmore Ill recheck all and let you know.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events