Forums

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

SSH Access through bitbucket pipeline using my own SSH key pair (permission denied error)

Yonirt
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 1, 2019

Hey guys,

 

I've been trying to configure a deployment workflow with bitbucket pipelines using my own SSH Key pair with this pipeline script:

image: atlassian/default-image:2

pipelines:
tags:
release:
- step:
name: Deploy to development
script:
- echo "Deploying to development"
- ssh ec2-user@xx.xxx.xx.xx /home/ec2-user/build.sh param1 param2

Unfortunately, I can not make it work since it gets stuck in the ssh connection returning:

+ ssh ec2-user@xx.xxx.xxx.xx /home/ec2-user/build.sh param1 param2 ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directoryPermission denied (publickey,gssapi-keyex,gssapi-with-mic).

 I'm using my own SSH Key pair which I installed following the next steps:

1) Generate the SSH Key (RSA) without a passphrase; 

ssh-keygen -f pipelineAccessKey -t rsa -N ''

2) Set the private key and the public key under Settings > SSH Keys (Pipelines) and fetch the fingerprint

bitbucket.png

3) Add the public key into ~/.ssh/authorized_keys in the remote server and done.

 

However when I use SSH keys generated automatically by Bitbucket works but I need using my own SSH Key pair in order to use it in other repositories.

 

If anyone has any idea what is happening here it would be awesome.

Thanks!

1 answer

0 votes
Graham Gatus
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 6, 2019

Hi @Yonirt 

I would first suggest trying out your generated key pair locally, from within the pipelines docker image, to rule out any issues with the keys or build script. 

ssh-keygen -f pipelineAccessKey -t rsa -N ''
chmod 600 pipelineAccessKey pipelineAccessKey.pub

# Ensure you now add the public key to the remote instance authorized keys file.

# Test from a local pipelines build container.
docker run -it -v $(pwd):$(pwd) -w $(pwd) atlassian/default-image:2 bash

# Once inside the running docker container, attempt to ssh to the remote.
ssh -i pipelineAccessKey ec2-user@<host> /home/ec2-user/build.sh param1 param2

I've tested with a newly instantiated t2.micro instance running Amazon Linux (ami-0c3228fd049cdb151) , and was able to connect successfully and execute a script in the ec2-user's home directory.

One possibility could be garbage characters introduced when copy/pasting keys from your machine into the pipelines UI. I would suggest using a tool such as 'pbcopy' (OSX) or 'xclip' (Linux) to copy the contents of the keys to the clipboard before pasting in the key in the pipelines UI to minimise the chance of copy/paste errors. Typical usage would be

cat <keyfile> | pbcopy

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events