If you don’t know how to view SSH certificates, we will show you how to implement it on Linux, macOS, and Windows. There are times when you really need to look at your SSH certificates on Linux. What for? Let’s say for example you need to add a certificate to authenticate to GitHub (or any other online service that requires SSH authentication).
You know you generated these SSH certificates, but how do you view them?
Those familiar with SSH probably already know the answer to this question.
For the rest, I’ll show you how easy it is to view these SSH keys so you can use them for third party services.
What do you need
The only thing you need to do this is access to the server or desktop (Linux, macOS or Windows) and the generated SSH key.
If you haven’t created your SSH key pair yet, you can do it with the command:
This command will generate a key pair, both public and private keys. The public key is the key that you send to the servers for SSH key authentication. When you try to log into this server, SSH compares the public and private keys. If these keys match, you will be allowed access. Everything is quite simple here.
How to view your SSH public key on Linux
There are two easy ways to view your SSH public key on Linux.
The first method is a little tricky because it uses the ssh-agent and ssh-add commands.
This is probably overkill for what you need, but it is a good way to view the key while requiring the password of your SSH key pair.
The command is like this:
ssh-agent sh -c 'ssh-add; ssh-add -L'
After successful authentication, your SSH public key will be shown in the terminal.
Then you can copy and paste it wherever you need. If you don’t want to remember one more command, you can simply use the cat command like this:
The above command will output your SSH key on your terminal without asking for a password.
How to view your SSH public key on macOS
Viewing keys on macOS can be done in a similar way to Linux.
Open a terminal window and enter the command:
Where USERNAME is your macOS username.
The above commands will output your SSH public key.
There is another interesting trick in macOS.
You can copy the contents of the SSH key directly to the clipboard without displaying the key using the pbcopy tool.
This command will be as follows:
cat ~/.ssh/id_rsa.pub | pbcopy
Once you’ve copied the key to your clipboard, you can paste it anywhere you want.
How to view your SSH public key on Windows
On Windows, you will use the type command to view the SSH public key like this:
Where USERNAME is your username.
The above command will display your SSH public key.
Then you can use the keyboard shortcut Ctrl + c to copy the contents of the file.
You can also do something similar to what we did on macOS (copy the SSH public key directly to the clipboard) using the following type and clip commands:
type C:UsersUSERNAME.sshid_rsa.pub | clip
Where USERNAME is your username.
Now you can paste this key anywhere.
How to view your private key
You will most likely never have to look at your private key.
After all, it is a secret that is never put on public display.
But, if you really need to view this key, you can follow the same steps as above, but remove the .pub from the filename (anyway).
Remember id_rsa is the private key and id_rsa.pub is the public key.
And that’s all it takes to view SSH public and private keys on Linux, macOS, and Windows.