sshbitbucketscp

Bitbucket pipeline error when uploading files


I have this pipeline in my bitbucket repo:

image: ubuntu:latest

pipelines:
  branches:
    develop:
      - step:
          name: Upload
          script:
            - apt-get update && apt-get install -y openssh-client
            - ls
            - echo "Creating modified_files.txt with manual specification"
            - echo "bitbucket-pipelines.yml" > modified_files.txt
            - echo "Modified files:"
            - cat modified_files.txt
            - echo "$EC2_KEY" > ec2_private_key.pem
            - chmod 600 ec2_private_key.pem
            - mkdir -p ~/.ssh
            - touch ~/.ssh/known_hosts
            - ssh-keyscan -H "$EC2_HOST" >> ~/.ssh/known_hosts
            - cat ~/.ssh/known_hosts
            - while IFS= read -r file; do
                scp -i ec2_private_key.pem -o StrictHostKeyChecking=no -r "$file" ubuntu@$EC2_HOST:$PATH_TEST"$file";
              done < modified_files.txt
            - rm ec2_private_key.pem modified_files.txt

but i got this error when i try to execute the scp command:

error in libcrypto permission denied (publickey)

I tried adding some parameters in the scp command but it didn't work


Solution

  • I found the solution.

    I needed to add the ssh key pair in the ssh keys section of the pipelines sections in repository settings.

    I found the solution here:

    https://support.atlassian.com/bitbucket-cloud/docs/set-up-pipelines-ssh-keys-on-linux/