Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Copy generated SSH public key with ssh-copy-id from pipeline image to remote server

I created a custom docker image based on Alpine. Moreover, I added a Python script to read secrets from our Vault server and use Rsync to deploy the repository to our servers.

Testing this script in a server or my own workstation was successful. However, When I tried to use it in Bitbucket pipeline it wasn't able to copy the public ssh key (generated from bitbucket ssh tab in pipeline settings). I went through the running image with some command to search for the keys and I find only the private key and no public key. I checked also some pipeline images from this project but still have the same issue. I am using the script from rsync deploy pipeline which looks like this:

#!/bin/bash## Bitbucket Pipelines#

"$(dirname "$0")/"

"Executing the pipe..."

setup_ssh_dir() {


# The default ssh key with open perms readable by alt uids


# The default known_hosts file

mkdir -p ~/.ssh || debug "adding ssh keys to existing ~/.ssh"
~/.ssh/authorized_keys chmod -R 700 ~/.ssh

if [ ! -f ${IDENTITY_FILE} ]; then
"No default SSH key configured in Pipelines."
exit 1 else debug "Using default ssh key"

${IDENTITY_FILE} ~/.ssh/pipelines_id
chmod 600
ssh-keygen -y -f
~/.ssh/pipelines_id > ~/.ssh/

if [ ! -f ${KNOWN_HOSTS_FILE} ]; then
"No SSH known_hosts configured in Pipelines."
exit 2

${KNOWN_HOSTS_FILE} >> ~/.ssh/known_hosts

if [ -f ~/.ssh/config ]; then

"Appending to existing ~/.ssh/config file"


echo "IdentityFile ~/.ssh/pipelines_id" > ~/.ssh/config
chmod -R go-rwx



The result I am getting when I execute an ssh-copy-id of the copied key:

 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/"
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/"

 Am I doing something wrong and why there is no trace of the public key inside the image when it runs in the pipeline. And what's the right way to copy it on pipeline execution. 

0 answers

Suggest an answer

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

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

185 views 2 4
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