How To Setup SSH Keys on CentOS 8

Setup SSH Keys on CentOS 8

In this tutorial we will show you how to setup SSH Keys. For those of you who didn’t know, Secure Shell (SSH) is a cryptographic network protocol designed for a secure connection between a client and a server. Generally, there are two ways for clients to access their servers – using password based authentication or public key based authentication. Using SSH keys for authentication is highly recommended, as a safer alternative to passwords.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation and setup SSH keys on CentOS 8 server.

Setup SSH Keys on CentOS 8

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Creating SSH keys on CentOS 8.

Start by logging into the source machine (local server) and creating a 4096-bit RSA key pair using the command:

After entering the command, you should see the following prompt:

To save the file in the suggested directory, press Enter. Alternatively, you can specify another location.

Next, the prompt will continue with:

Finally, the output will end by specifying the following information:

Step 3. Copy Public Key to CentOS Server.

Start by typing the following command, specifying the SSH user account, and the IP address of the remote host:

Once the user is authenticated, the content of the public key file (~/.ssh/id_rsa.pub) will be appended to the remote user ~/.ssh/authorized_keys file, and connection will be closed.

Lastly, the output tells you the number of keys added, along with clear instructions on what to do next:

Step 4. Connect to Remote Server Using SSH Keys.

After completing the steps above, you should be able to log in to the remote server without being prompted for a password:

Step 5. Disable Password Authentication.

Although you managed to access the CentOS server without having to provide a password, it still has a password-based authentication system running on the machine. This makes it a potential target for brute force attacks. Follow the steps below to disable SSH password authentication:

Open the SSH configuration file /etc/ssh/sshd_config:

Once you are done save the file and restart the SSH service:

Congratulation’s! You have successfully installed SSH server. Thanks for using this tutorial for installing and configure SSH keys on CentOS 8 systems. For additional help or useful information, we recommend you to check the official SSH website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!