How can I use SSH in Bitbucket Pipelines to update files in server?

Hi Guys!

I'm struggling to make pipeline to work. I just want Bitbucket simply update the changes to my server.


I already installed git in my server. I can ony access my server via ssh. I also already included my Host address in SSH Keys, and Fingerprint is already being displayed.


Here is my current yml configuration:

# Check our guides at for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: samueldebruyn/debian-git

    - step:
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD ftp://123.45.678.901/

Are the informations correct? What I'm missing?

I just want to update my server once I commit and push the files to bitbucket.

Can you guys help me?

1 answer

I haven't tried it the way your are yet, but I have had success using scp:

- mkdir -p ~/.ssh
umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa

- scp -i ~/.ssh/id_rsa -P $SERVER_PORT -r $DIRECTORY_TRANSFER_LIST $USERNAME@$SERVER_IP_ADDRESS:~/path/to/project

Where $DIRECTORY_TRANSFER_LIST is the name of the project directory you wish to transfer

Hi @Shane Fast

Thanks for your response. When I access my server, I have the following folders: Maildir , and logs.

So based on your example, I should use:

- scp -i ~/.ssh/id_rsa -P $SERVER_PORT -r $USERNAME@$SERVER_IP_ADDRESS:~/

Is this correct?

Also should I use id_rsa or this is something that I also have to change?

Yes, based on the info you provided that appears to be the correct command.

as for id_rsa - its just the standard name for the key file. You can name it whatever you want as long as its the same name as the command preceeding it:

- umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/<name of file holding my private key>

- scp -i ~/.ssh/<name of file holding my private key> -P .....

Saving it into the .ssh directory and using umask 077 are required for setting the correct permissions on the key file. Without the correct permissions on the key file any remote commands or transfers will be rejected for built in security reasons.

Hi @Shane Fast

Thanks for your response once again.

Sorry for my many questions, I'm really a beginner on this. 

Regarding this line: echo $MY_SSH_KEY 

Should I include the SSH public key (a really big number), or should I use this variable ($MY_SSH_KEY) as it is?

Any update on this, i'm stuck?


I'm getting: bash: scp: command not found

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

655 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you