SSH (Secure Shell) is an encrypted protocol to connect with a remote device. By default, it works on TCP port 22. There are two methods to connect with the remote server using SSH, one is by using the password authentication, and another way is to authenticate is by the public key. In this tutorial, we will learn how to generate an SSH key to be used for key-based authentication in CentOS 8.

Generate SSH Key

Before generating the SSH Key. Firstly, verify the SSH is installed or not. To verify, open up the terminal and type the following command.

# ssh –V

Check OpenSSH Version

After verifying the SSH package. Now I am going to generate the SSH key, using the following command.

# ssh-keygen

To tighten up the security, you can mention the encryption algorithm according to your need, as shown below.

# ssh-keygen –t rsa

# ssh-keygen –t rsa –b 4096

ssh-keygen

After entering the above command, the following output should appear.

Name of the key file

To save the file in a suggested directory press enter.

Next, it will prompt you to enter the passphrase, leave it empty, and press enter. The following output should appear.

Generating SHA256 key

The SSH key is successfully generated. You can verify it by using the following command to view your SSH key.

SSH Key created successfully

This command will print your SSH key.

Conclusion

In this tutorial, we learned how to generate the SSH authentication key in CentOS8. We also saw how to generate the SSH key using a specific encryption algorithm.

How to Generate an SSH Key in CentOS 8
Avatar

Karim Buzdar

About the Author: 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.