There are multiple reasons why one would want to find the SSH keys in Ubuntu such as one may want to inspect if the keys are generated in the first place or not.
If not, the user can generate SSH keys to move ahead. Another reason can be a troubleshooting where you start with locating keys.
Sure, you may have your own reasons. But the question is how do you find the SSH keys in Ubuntu Linux?
Well if you stored the SSH keys in the default directory, then you can use the ls command to list the contents of the
Want more details? Here you have it.
Find SSH keys in Ubuntu
In this tutorial, I will walk you through two ways to find SSH keys in Ubuntu or any other Linux distribution:
- By listing the contents of the
- Using the find command (useful if you used a different directory to store keys)
Let's start with the first one.
Find SSH keys by listing the contents of the SSH directory
While generating the SSH it will ask you to decide the directory in which you want to store the SSH keys and if you went with the default settings, you can use this method.
To list the content of the
~/.ssh directory (yes, it is a hidden directory), use the ls command as shown here:
Here, you will find 3 files (or 4 if you've been using SSH for a long time) and each has a meaning:
id_rsa: the private SSH key which is not meant to be shared with anyone and used for user authentication.
id_rsa.pub: the public key which can be freely shared with anyone.
known_hosts: it stores the public keys of the hosts that were accessed by a user.
known_hosts.old: it is a backup created by your system when changes are made to the original
To learn more about the
known_hosts file, I would recommend checking out the detailed guide on known_hosts in Linux:
Find SSH keys using the find command
Imagine you used a different location to store SSH keys and now you don't know what directory it was. That's where this method kicks in to help you out.
All you have to do is execute the find command in the following manner:
find / -name "id_rsa*" 2>/dev/null
The above command will search for the
id_rsa title in the root directory and will redirect errors to the
More on SSH
You can use the secure copy protocol to send and receive files from the server and client. Want to know how? Here's a detailed guide to using SCP command:
I hope you will find this guide helpful.