When I copy SSL certificates from windows files, it makes it hard for me to put them directly on server to configure SSL certificates. Because UNIX treats the end of line differently. A CTRL-M character is visibly displayed at the end of each line as ^M in vi.
Have a look at the following content. Its an SSL key which I copied from a windows file to a normal file in Linux. You find that each line is ended with a control character. ie. ^M or CTRL+M.
—–BEGIN RSA PRIVATE KEY—–^M
MIICXAIBAAKBQC8z9kWT8m7w/SdipRrA6qS5PopYSFqAuKs^M
AWJdfjrpIv8MMzXoV1THzoqKDGMR8uaKbManEgSi9OmGUFY^M
zJvjmethqRhFn/2ICZJPR96tUWoFFSZV7/+UBNQPNwIDAQAB^M
AoGAdfrOZIiEs1MeTR6l3PX0/mSQ11w7+FkbOG2ZAGCbAQis^M
I/xv5+GBVw44XDJ8DtKQhJZINYcl8fYsrNKCgpgg64UoRjWYv6^M
XBlae9kpjItMiJsYJdFy/BFI5Cs9RYN9AesuPkCQQDi7jiStLlHEgE5^M
YTCF2Y6k5v255oOKNEEuKoamDCeG6UF/EX72in3KfHgrVKK8^M
VEWhkG+1AkEA1P+YM9Llmz16Cv3PSYA3Z0azgyvjBwhjCwg^M
1E3upSFqhGL8DNsETsMMt/ZeBu//xuwOBqrJ9Qpz0xbESSwk^M
1+cUSOORLjsXGpzp+xNcE+U4E94LvoA77HDDh1QJATWCM^M
7TKSpf9FYjnXqDxPlAIAHoSQshY/Y06orFlO7sT9uksyO69J4WG^M
vO9oqerPvGAQJBAKM8/kZaXMvhGmmMWrYxn/KuLcMmwfW^M
k0hEDnf0cAFsP4MYgEliHBnjOYmsO5nOde0JU4ZTsXI=^M
—–END RSA PRIVATE KEY—–
How do we get rid of this to get this SSL key working on a Linux box?
All that you need to do is remove the ^M characters at the end of all lines in vi, use:
:%s/^V^M//g
The ^v is a CONTROL-V character and ^m is a CONTROL-M. When you type this, it will look like this:
:%s/^M//g
In UNIX, you can escape a control character by preceding it with a CONTROL-V. The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).
May 23rd, 2008 at 12:06 pm
coool ……………
May 24th, 2008 at 11:05 am
You can also use dos2unix or the flip -u commands to translate. In vim itself, you can do the following too:
: set ff=unix
:wq!