I have stored my private key file in AWS SSM Parameter store. I want to retrieve just the private key value from the parameter store and save it as an id_rsa file locally using aws cli.
This article: https://github.com/aws/aws-cli/issues/2742 shows me exactly how i can do that using sed. however I still get a character returned after "-----END RSA PRIVATE KEY-----" which i want to remove using sed.
This is my command i run on command line:
aws --region=us-east-1 ssm get-parameters --names "mykey" --with-decryption --output text 2>&1 | sed 's/.*----BEGIN/----BEGIN/'
And the output is:
----BEGIN RSA PRIVATE KEY-----
some text here
-----END RSA PRIVATE KEY----- 2
Notice the 2 in the end of the last line. I want to get rid of anything after -----END RSA PRIVATE KEY----- as well.
What do i need to add to my sed command to achieve that?
2>&1? Are you redirecting stderr to stdout? Why? Remove2>&1and it should fix your problem. - helloV2>&1as you are right, it is not needed. However that still does not remove the trailing2in the end of the last line. So by adding the following did give me the desired output:sed 's/KEY-----.*/KEY-----/'- H RH