1

I found out that I can view the contents of a PEM file by pressing the Spacebar, it's not possible to select the text.

How can I copy and paste the file contents, because I need to paste it in this text field:

The contents of my PEM file look weird after opening it in the terminal. Is this normal? Because when I open the file with Spacebar the contents look completely different and much more normal than these lines.

In Terminal:

-----BEGIN CERTIFICATE-----
MIIFtzCCBJ+gAwIBAgIIRA1/KqHYmg8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV
BAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3Js
ZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3
aWRlIERldmVsb3BlciBSZWxhdGlvbnMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkw
HhcNMTkwNjE4MTQzNTE1WhcNMjAwNjE3MTQzNTE1WjCBtjE5MDcGCgmSJomT8ixk
...
-----END CERTIFICATE-----
1

I found out that I can view the contents of a PEM file by pressing the Spacebar, it's not possible to select the text.

This feature is called Quick Look in macOS. Quick Look is a handy tool to quickly view a file's content without launching any app.

To quickly copy the contents of the PEM file to clipboard, launch Terminal.app, change to the directory containing the PEM file and run the following command (Here assume the name of the PEM file is pemfile.pem and it is located in ~/Downloads directory):

pbcopy < ~/Downloads/pemfile.pem 

The command won't output anything in Terminal. The PEM file contents are now copied into clipboard.

Now you can go to the desired text field and paste the copied contents by using the macOS paste keyboard shortcut Command + V.


The contents of my PEM file look weird after opening it in the terminal. Is this normal? Because when I open the file with Spacebar the contents look completely different and much more normal than these lines.

The contents are completely normal. That's how the contents of a PEM file looks. The actual textual contents of the PEM file are not shown when using Quick Look. To view full contents of the PEM file, open it using a text editor.

  • Just chain a pbpaste to the end of your solution and you can see the contents of the clipboard printed to standard out. – fd0 Jun 24 at 17:30
  • The contents look weird after opening the PEM file in Terminal. See my question. – Hobbit7 Jun 24 at 17:55
  • Is the RSA key hidden in this long text when I open the PEM file in the Terminal? – Hobbit7 Jun 24 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .