Another example of executing SSH commands on remote server in Bitbucket pipeline on commit

We should allow SSH access from Bitbucket to the target server. For this - you should have a keypair - generate it with:

ssh-keygen
and then:
ssh-copy-id user@target.server
Next, encode private key in base64:
base64 -w 0 < ~/.ssh/id_rsa
and copy the output.

Then go to Bitbucket repo -> Repository Variables
Enter the name SSH_KEY and the above value, Tick Secured and press Add.

To make pipelines run, you need to have a bitbucket_pipelines.yml file in the branch dev with following contents:
pipelines:
  branches:
    dev:
      - step:
          script:
            - pipe: atlassian/ssh-run:0.8.0
              variables:
                SSH_USER: 'user'
                SERVER: 'x.x.x.x'
                SSH_KEY: $SSH_KEY
                COMMAND: 'echo "Executing hook.sh" && /home/user/hook.sh'
                EXTRA_ARGS:
                  - '-o ControlMaster=auto'
Basically it will connect to the server with an user user and target key SSH_KEY and will execute:
echo "Executing hook.sh" && /home/user/hook.sh
on each commit on dev branch on Bitbucket