I am trying to setup vagrant box using shell script where in I am storing key
and cert
files. Normal format of any cert or key file is as below
-----BEGIN CERTIFICATE-----
MIIDzzCCAregAwIBAgIJAP384f0KeRndMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV
....
0+ZQ+Yxjzs69VHdPJbzu3cxjNQ==
-----END CERTIFICATE-----
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6qoE3hNniDqD7
....
wr5wa+bGBgNzIBLS5j9F9Kul
-----END PRIVATE KEY-----
However when I check on vagrant box it looks like below.
-----BEGIN CERTIFICATE----- MIIDzzCCAregAwIB ..... 69VHdPJbzu3cxjNQ== -----END CERTIFICATE-----
-----BEGIN PRIVATE KEY----- MIIEvgIBADANBgkqhki .... OB7jnwaqq wr5wa+bGBgNzIBLS5j9F9Kul -----END PRIVATE KEY-----
(basically, everything in one row)
Due to which Apache2 has errors in the log. Now I want to convert these keys to their proper format. I did try below
cat server.crt | tr " " "\n"
cat server.crt | tr "\ /" " "
but it didn't help.
-----BEGIN
CERTIFICATE-----
MIIDzzCCAregAwIBAgIJAP384f0KeRndMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV
0+ZQ+Yxjzs69VHdPJbzu3cxjNQ==
-----END
CERTIFICATE-----
This is what I am getting as a result of sed -i 's/ /\n/g' *.crt
command. after END it goes to next line due to space character.
Objective here is keep the first and last line as it is and format the content between them.