unixssh-keysbamboo

Private ssh key from one line environment var


I have my privkey.pem private key in the form

-----BEGIN RSA PRIVATE KEY-----
xxx
-----END RSA PRIVATE KEY-----

I need to make a Bamboo task to connect to a server via ssh using this key. Unfortunately I see that Bamboo can store only variables in one line, so if I paste the key all the "\n" get stripped out so this doesn't work:

eval $(ssh-agent -s)
echo "${bamboo.sshKey}" | ssh-add - > /dev/null
scp -vvv -o StrictHostKeyChecking=no .....

Is there a way to have a private key in a "one line" format readable from ssh-add? Or, is there a clean way to reparse the key to get again the stripped "\n"?


Solution

  • I do not know Bamboo. So possibly, there's a better solution. But one way would be to use some symbol to separate the lines in the variable. And then use something like sed or tr to convert the symbol to a new line, when feeding it to the ssh-add.

    See Replace comma with newline in sed on MacOS?