Bitbucket ssh private key Invalid format

Hi guys, I stored my bitbucket ssh key in a separate yaml file as a variable. When I start my pipeline, my resource gets
“run check step: run check step: check: resource script ‘/opt/resource/check []’ failed: exit status 1
stderr:
Error loading key “/tmp/git-resource-private-key”: invalid format”
I’ve tried a sorts of formats and nothing seems to work. Any help or thoughts is much appreciated. Thank you!

Here is what I have:

resources:

  • name: privaterepo
    type: git
    source:
    uri: ssh://git@bitbucketrepo.git
    branch: master
    private_key: ((private-repo-key))

and then my keys file

private-repo-key: |
-----BEGIN RSA PRIVATE KEY-----
my bitbucket ssh ket from my account settings
-----END RSA PRIVATE KEY-----

It’s hard to tell because you didn’t put your code in a code block but I’d expect what you have to work provided the vars file is spaced like this:

private-repo-key: |
  -----BEGIN RSA PRIVATE KEY-----
  my bitbucket ssh ket from my account settings
  -----END RSA PRIVATE KEY-----

It may also need to be LF line endings but I’m not sure on that.

1 Like

Thanks for the response! I don’t know how to do a code block. But they are spaced out. I’ve tried all sorts of spacing formats in my vars file. My key is super long . It does start with ssh-rsa and ends with a label user@user-ll-1234 But i’ve removed those parts from the file.

Are you sure you provided the privateKey and not by accident the publicKey?

I just checked some of my ssh keys - the public ones start with “ssh-rsa” and end with a label like “USERNAME@HOST”.

You can create a new keypair using

ssh-keygen -f ./test-key -N ""

This will create a new keypair “test-key” without a passphrase in your current directory. You now can check how the publicKey and the privateKey look like :slight_smile:

2 Likes

Awesome, thank you so much. I am providing the public key. I’m going to try and figure out what my private key is then. Thank you!