8

i have ssh-key, something like this

-----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY-----

Of course this key does not work. When i am doing manual things, something, like this

-----BEGIN RSA PRIVATE KEY----- 
my_super_secret_password 
-----END RSA PRIVATE KEY-----

It works. When i am deleting this -----BEGIN RSA PRIVATE KEY----- and this -----END RSA PRIVATE KEY-----, my ssh-key does not work.

So, the question. How, i can make automatically via some command, like sed or awk, or any other command, how can i make from this string

-----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY-----

these three strings

-----BEGIN RSA PRIVATE KEY----- 
my_super_secret_password 
-----END RSA PRIVATE KEY-----

Thanks for your help. If you know any other answer on this question, i am glad to hear you. The reason, why i need it, because i have secret keys storage in AWS Secret Manager. So, this manager stores keys only in one line.

1

2 Answers 2

19

I would personally base64-encode the key, store it, then base64 decode it when you need it.

Encode:

echo "-----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY-----" | openssl base64 | tr -d '\n'

Decode:

echo "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLSBteV9zdXBlcl9zZWNyZXRfcGFzc3dvcmQgLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K" | openssl base64 -A -d
1

Something like this, quick and hacky.

echo "-----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY-----" | sed 's/\(KEY----- \)/\1\n/' | sed 's/\(-----END\)/\n\1/'

Not the answer you're looking for? Browse other questions tagged .