git ftp push Pipeline failing "SSH public key authentication failed: Unable to open public key file"
Asked by Marc Loeb:

I try to make git ftp push pipline work from bitbucket to aws lightsail with a bitnami image. I followed the steps here, but cannot find my error:

<https://community.atlassian.com/t5/Bitbucket-questions/Pipeline-git-ftp-sftp-SSH-keys-convert-to-PEM/qaq-p/1480543>

my yml file looks like this:

image: php:7.3.5

pipelines:  
branches:  
master:  
- step:  
name: Deploy to aws lightsail bitnami production  
deployment: production  
script:  
- apt-get update  
- apt-get -qq install git-ftp  
- apt-get install -y ssh  
- git ftp push -vv -u bitnami --key /opt/atlassian/pipelines/agent/ssh/id_rsa sftp://x.x.x.x:22/opt/bitnami/wordpress/wp-content

A connection is made, but it seems the public key cannot be found. I created a SSH Pipline key and a fingerprint in repro settings-\>pipeline.

And I copied the public key to the home/bitnami/.ssh/authorized_keys file with nano.

PS:  
I answered my question myself. Still I wonder where the public key is. The solution I found just recreates the public key - can this be on purpose? So if anybody knows the internals, I would be very interested what the path of the public key is. I revert my mark as answer so somebody still gets the credits if answerting.  
Thanks!

The exact error message is here:  
+ git ftp push -vv -u bitnami --key /opt/atlassian/pipelines/agent/ssh/id_rsa sftp://x.x.x.x:22/opt/bitnami/wordpress/wp-content  
Mon Oct 25 11:10:55 UTC 2021: git-ftp version 1.3.1 running on Linux xxxxxxxxxxxxxxxxx-ffdnv 5.6.0 #1 SMP Thu Nov 12 07:09:22 UTC 2020 x86_64 GNU/Linux  
Mon Oct 25 11:10:55 UTC 2021: Host is 'x.x.x.x:22'.  
Mon Oct 25 11:10:55 UTC 2021: User is 'bitnami'.  
Mon Oct 25 11:10:55 UTC 2021: No password is set.  
Mon Oct 25 11:10:55 UTC 2021: Using ssh private key file /opt/atlassian/pipelines/agent/ssh/id_rsa  
Mon Oct 25 11:10:55 UTC 2021: Using ssh public key file /opt/atlassian/pipelines/agent/ssh/id_rsa.pub  
Mon Oct 25 11:10:55 UTC 2021: Added missing trailing / in path.  
Mon Oct 25 11:10:55 UTC 2021: Path is 'opt/bitnami/wordpress/wp-content/'.  
Mon Oct 25 11:10:55 UTC 2021: Syncroot is ''.  
Mon Oct 25 11:10:55 UTC 2021: The remote sha1 is saved in file '.git-ftp.log'.  
Mon Oct 25 11:10:55 UTC 2021: CACert is ''.  
Mon Oct 25 11:10:55 UTC 2021: Insecure is ''.  
Mon Oct 25 11:10:55 UTC 2021: Retrieving last commit from sftp://bitnami:***@3.125.44.139:22/opt/bitnami/wordpress/wp-content/.  
* Trying x.x.x.x...  
* TCP_NODELAY set  
* Connected to x.x.x.x (x.x.x.x) port 22 (#0)  
* SSH MD5 fingerprint: xxxxxx  
* SSH authentication methods available: publickey  
* Using SSH public key file '/opt/atlassian/pipelines/agent/ssh/id_rsa.pub'  
* Using SSH private key file '/opt/atlassian/pipelines/agent/ssh/id_rsa'  
* SSH public key authentication failed: Unable to open public key file  
* Failure connecting to agent  
* Authentication failure  
* Closing connection 0  
curl: (67) Authentication failure  
Mon Oct 25 11:10:56 UTC 2021: fatal: Could not get last commit. Network down? Wrong URL? Use 'git ftp init' for the initial push., exiting...


Answers:
author: Marc Loeb
body: I continued to work on it and found another post in related community content:

<https://community.atlassian.com/t5/Bitbucket-Pipelines-questions/Git-FTP-not-finding-pipeline-SSH-key/qaq-p/1756484>

This worked - I used the bitbucket repo settings-\>ssh keys to generate a new public and private key. Then copied the private key from bitbucket to .ssh/authorized_keys; do not delete the public key inside there, it is needed by Aws and other tools you connect with.

Funny I was not able to find the post above - as usual understanding grows while working on the topic; including the right wording.


Tags: bitbucket-cloud

cloud