Setting up SSH on custom Bitbucket Pipes

March 24, 2021

In this post I'll show you how you can configure SSH keys for your custom Bitbucket Pipe. This requires a tiny bit of setup, as there is no ~/.ssh directory on the docker container. This makes using SSH a little more tricky, especially when you're using tools like git or other deployment tools that hide the actual SSH configuration.

Quick rant: who the heck named custom pipeline tasks "pipes". It's pretty much impossible to Google! I just get pipeline results.

In your shell script you'll just need to add the following:

mkdir -p ~/.ssh
cp /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp ~/.ssh/id_rsa
cp /opt/atlassian/pipelines/agent/ssh/known_hosts ~/.ssh/known_hosts
chmod -R go-rwx ~/.ssh/

It's important to copy the id_rsa_tmp AND known_hosts. Without the known hosts file you'll be unable to connect to remote origins. The id_rsa_tmp represents the custom private SSH key that is added into bitbucket pipelines when you follow their guide here:

Make sure ssh is installed on your docker image of course too!