3

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"?

edoedoedo
  • 1,469
  • 2
  • 21
  • 32

2 Answers2

3

I realize I am a bit late but solutions with sed and tr didn't work well for me. I ended up using base64 and base64 -d, e.g.

echo "${bamboo.sshkey}" | base64 -d > id_rsa
chmod 600 id_rsa
export GIT_SSH_COMMAND='ssh -i id_rsa -o StrictHostKeyChecking=no'
....
rm id_rsa

Using a variable name like sshkey makes Bamboo mask it.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Dario Pedol
  • 2,070
  • 14
  • 24
0

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992