1

I have a ssh key that I am storing in AWS Parameter store. As part of some process I retrieve the key from the paramstore. However, when I use it in ssh I get a invalid format error. When I inspect the file, instead of the normal key file like:

-----BEGIN OPENSSH PRIVATE KEY-----
<line of chars>
<line of chars>
...
<line of chars>
-----END OPENSSH PRIVATE KEY-----

What I find is that the file instead looks like:

-----BEGIN OPENSSH PRIVATE KEY-----\n<line of chars>\n<line of chars>\n...<line of chars>\n-----END OPENSSH PRIVATE KEY-----

AFAIK, these two files should render in the same way, but they don't, and I suspect thats why the ssh command is failing.

1) How do I fix the key file such that it will now be in the correct format? I cant replace the newlines with other newlines. Ideally I would use sed or some other *nix command, but I don't know what to to the file.

2) Why is it that sometimes newlines get represented as actual newlines, and sometimes get represented as string characters?

EDIT: Basically I want to do this but in reverse.

Logister
  • 1,852
  • 23
  • 26

1 Answers1

1

Found the answer by adapting this: cat ~/.ssh/weirdpemkey | sed 's/\\n/\'$'\n/g'

Logister
  • 1,852
  • 23
  • 26