SSH keys in environment variables

RandallB picture RandallB · Aug 8, 2012 · Viewed 13.9k times · Source

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.

Answer

RandallB picture RandallB · Aug 8, 2012

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.)