Good afternoon, I have a private ssh key, I first write it to a variable (so far for tests in bash, it is assumed that the variable will be in gitlab), then I rewrite it to a file:
ID_RSA="-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END RSA PRIVATE KEY-----"
echo $ID_RSA > ~/.ssh/id_rsa
But this does not work, because the variable writes the entire key to a string and transfers the string to a file. But as I experimented, I need a format not in one line, but with line breaks. But I don't know how to edit the file with a command. I tried to wrap lines after spaces, but this is not the right option, since the results are also wrong:
sed 's/ /\n/g' ~/.ssh/id_rsa
The result is almost perfect, but not quite)
-----BEGIN
RSA
PRIVATE
KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END
RSA
PRIVATE
KEY-----"
And you need it like this:
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END RSA PRIVATE KEY-----
With the following option, I experimented in the console, but caught an error when executing the command. The command is like this:
ssh-add - <<< "${SSH_PRIVATE_KEY}"
As for the hashicorp vault, for some reason my colleagues want to refuse it in principle, therefore, I don’t consider this option either (I mean storing not a variable, but a file with subsequent encryption).