Issue
What if you want to put your ssh private or public key into environment variable and access it on a CI system?
A key looks like this, so how can you convert it in a base64 string without newlines?
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAICS0Scec9oD2raCs5HoZyQuZCPXJAVZvIJ+OooR0faAAAAJBsx4YgbMeG
IAAAAAtzc2gtZWQyNTUxOQAAACAICS0Scec9oD2raCs5HoZyQuZCPXJAVZvIJ+OooR0faA
AAAEDd1JmV4ligped6DH18jnlyEriUfNve+80vexKOOZjUwQgJLRJx5z2gPatoKzkehnJC
5kI9ckBVm8gn46ihHR9oAAAABmF3c2JvdAECAwQFBgc=
-----END OPENSSH PRIVATE KEY-----
Solution
First generate your keys or you can use any existing keys whether it's RSA or ED25519
ssh-keygen -t ed25519 -C "[email protected]"
Encode it into base64
cat id_ed25519 | base64 | tr -d \\n
Or
cat <filename> | base64 -w 0
suggested by @GPM
Now you can copy paste the output anywhere you want, this should give you a string with 0 newlines.
To verify
echo your_encoded_string | base64 --decode
You should see the same key as you had in your file.
Answered By - Shivam Answer Checked By - Clifford M. (WPSolving Volunteer)