Bitbuket pipeline - how to set ssh

Viewed 4101

When my pipeline runs, I am getting the below errors:

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/config
debug1: key_load_private_type: incorrect passphrase supplied to decrypt private key
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
lost connection

This is my .yml file:

image: maven:3.3.9

pipelines:
  default:
    - step:
        caches:
          - maven
        name: Build
        script: # Modify the commands below to build your repository.
          - echo "Build Start"
          - mvn package
          - echo $BUILD_DIR
          - mv target/**.jar target/transpoDirect.jar
        artifacts:
          - target/**.jar
    - step:
        name: Deploy
        image: maven:3.3.9
        script:
           - ls -la .
           - scp -i ~/.ssh/config -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/.
           - ssh -p 7822 -i ~/.ssh/config -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart

What I have tried is that chmod the ~/.ssh folder and files there to 777

The hostName variable is set in the repositories' settings.

Re-generated the key. Pasted in the authorize_keys file in the remote server, but I'm still getting the same error

Location of authorized_keys:

enter image description here

================================================================

This is what is working:

  1. Deleted the SSH keys from bitbucket's pipeline's.
  2. Generated the SSH key on the remote server by using: ssh-keygen
  3. Used default for the above command, and don't set passphrase.
  4. Default location where keys are generated is: /root/.ssh
  5. .ssh folder is hidden. Using winSCP you can unhide the hidden folders.
  6. Copied the content of id_rsa.pub from remote server and pasted into bitbucket's SSH.
  7. Created authorized_keys with the contents of id_rsa.pub inside /root/.ssh
  8. Copied the the content of id_rsa from the remote server and pasted into bitbucket's SSH.
  9. This copies the jar to the remote server:

    • scp -i /root/.ssh -4 -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/.
  10. This restarts the service as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

    • ssh -4 -p 7822 -i /root/.ssh -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart
2 Answers

This is what is working:

  1. Deleted the SSH keys from bitbucket's pipeline's.
  2. Generated the SSH key on the remote server by using: ssh-keygen
  3. Used default for the above command, and don't set passphrase.
  4. Default location where keys are generated is: /root/.ssh
  5. .ssh folder is hidden. Using winSCP you can unhide the hidden folders.
  6. Copied the content of id_rsa.pub from remote server and pasted into bitbucket's SSH.
  7. Created authorized_keys with the contents of id_rsa.pub inside /root/.ssh
  8. Copied the the content of id_rsa from the remote server and pasted into bitbucket's SSH.
  9. This copies the jar to the remote server:

    scp -i /root/.ssh -4 -P 7822 -v -o StrictHostKeyChecking=no target/*.jar root@$hostName:/var/transpoDirect/.

  10. This restarts the service as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

    ssh -4 -p 7822 -i /root/.ssh -v -o StrictHostKeyChecking=no root@$hostName sudo service transpoDirect restart


Further notes: The file should be put in the $HOME/.ssh/authorized_keys You can check where $HOME is by eval echo "$HOME" Also, something to understand is that id_rsa is the private file - this means that this file is not to be shared, but the id_rsa.pub is the public file and this is the file to be given to the other server.

The private key you're using with that SSH key has a passphrase, but you aren't specifying the passphrase anyplace in your YAML. You can either generate a new key for Pipelines's exclusive use, or you can upload a copy of that existing key that doesn't have a passphrase, or you might be able to use environment variables to provide the passphrase.

Related