Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 822
RandallB Avatar asked Aug 08 '12 02:08

RandallB


People also ask

What is SSH environment variable?

Tetiana Markova | September 13, 2016. Environment variables represent a kind of placeholders, where you can store the frequently used parameters' values or strings in order not to specify them manually in the code each time they are needed.

Where is the best place to store SSH keys?

SSH keys are typically configured in an authorized_keys file in . ssh subdirectory in the user's home directory. Typically a system administrator would first create a key using ssh-keygen and then install it as an authorized key on a server using the ssh-copy-id tool.

Where do I put SSH public key?

You need to be able to transfer your public key to the remote system. Therefore, you must either be able to log into the remote system with an established account username and password/passphrase, or have an administrator on the remote system add the public key to the ~/. ssh/authorized_keys file in your account.

How do I find my SSH key?

Open a terminal and use the ssh-keygen command with the -C flag to create a new SSH key pair. Replace the following: KEY_FILENAME : the name for your SSH key file. For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh-key.


2 Answers

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

like image 127
RandallB Avatar answered Nov 16 '22 02:11

RandallB


If you would like to read from the key file, this works:

heroku config:set PRIVATE_KEY="$(cat id_rsa)"
like image 27
Harrison Powers Avatar answered Nov 16 '22 03:11

Harrison Powers