Search code examples
unixherokusshprivate-key

SSH keys in environment variables


So I'm setting up a really awesome hubot setup which will automatically deploy code from github to heroku, via a free heroku nodejs app. I'm having trouble checking out the repo properly on AWS. I created SSH keys on the remote box, had them working and verified it. Then, I added them as Heroku environment variables like this:

~$ heroku config:add PRIVATE_KEY="...
aoijsdfasoidjfasodijfasodifjaodsifjasdofija"

I then try to echo both the public and private keys back to their normal location in .ssh/id_rsa, but they ask me for a passphrase, which I didn't set, and always fail.

Any idea how to successfully write a key to an environment variable? I think it's something to do with the linebreaks not showing up correctly.


Solution

  • AH! Of course.

    If you do echo "$VAR" it retains its formatting. Updating my scripts now.

    (i had been working on this all day. Thank you rubber duck.)