Linux Commands

What is the known_hosts File for ssh in Linux?

SSH, known as Secure Shell protocol, manages and accesses the remote systems by using an encrypted connection between the users and remote machine. In Linux systems, SSH is the most common method to connect to your servers or machines remotely and make the connection more secure through dual-key encryption remotely. It is important for both remote and client machines to make sure that they are connected with the correct intended machine.

When the first-time connection is established, the client stores the host keys of the host. The host key is an encrypted key that is used to verify the machine’s identity. These hosts keys are stored at locations ‘/etc/ssh/known_hosts’ and ‘.ssh/known_hosts’ in each user’s home directory. In this article, we will talk about what is known_hosts file for ssh in Linux distribution and how you can list its content through terminal.

Purpose of Known_hosts file

The known_hosts File is a client file containing all remotely connected known hosts, and the ssh client uses this file. This file authenticates for the client to the server they are connecting to. The known_hosts file contains the host public key for all known hosts. The use of this file is optional, but, if used then it is prepared by the system administrator. It automatically maintains the per-user file in the system. Each time a user connects with an unknown host and the unknown host key is added to this file. However, if the machine hacks or gets compromised, hackers can use the know_hosts file, view the list of all machines connected to this machine, and target those machines. To avoid this risk, not all IP addresses in the known_host key are defined in the plaintext format.

To access the content of the known_host file, type the following command to open this file in your favorite text editor through the terminal:

$ sudo nano ~/.ssh/known_hosts

Example

The format of the known_hosts file is given below:

Conclusion

We have explained in this article what the purpose of is known_hosts file for ssh in Linux and how you can access its content through the command line. After reading this article, I hope you have a piece of good knowledge about the known_hosts file.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.