Title says it all really. I'm trying to set an RSA private key in /etc/environment. Things I've tried include wrapping the variable in single and double quotes, add a backslash at the end of each line and adding '\n' at the end of each line.
Asked
Active
Viewed 3,633 times
3
-
1Answered on [so]. See shell - How to Export a Multi-line Environment Variable in Bash/Terminal e.g: RSA Private Key - Stack Overflow – DavidPostill Feb 28 '22 at 17:32
-
1May I ask what is the point of putting private keys in /etc/environment? That's loaded into the environment of most processes – it is much less safe than just storing them in a normal file... – u1686_grawity Feb 28 '22 at 18:17
1 Answers
4
From Stackoverflow:
export the key
export PRIVATE_KEY=`cat ./gitbu.2018-03-23.private-key.pem`
test.sh
#!/bin/bash
echo "$PRIVATE_KEY";
If you want to save the key to a .env file with the rest of your environment variables, all you needed to do is "wrap" the private key string in single quotes in the .env file ... e.g: sh exports HELLO_WORLD='-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA04up8hoqzS1+APIB0RhjXyObwHQnOzhAk5Bd7mhkSbPkyhP1 ... iWlX9HNavcydATJc1f0DpzF0u4zY8PY24RVoW8vk+bJANPp1o2IAkeajCaF3w9nf q/SyqAWVmvwYuIhDiHDaV2A== -----END RSA PRIVATE KEY-----'
So the following command will work:
echo "export PRIVATE_KEY='`cat ./gitbu.2018-03-23.private-key.pem`'" >> .env
Followed by:
source .env
Now the key will be in your .env file and whenever you source .env it will be exported.
mashuptwice
- 3,244