SSH (Secure Shell) keys provide a secure way of logging into a remote Linux system. They are an alternative to using a password-based login, and are often more secure because they use public-key cryptography to encrypt the connection. In this article, we will explain how to set up SSH keys on Rocky Linux 8.
Before we begin, it’s important to note that this tutorial assumes that you already have a Rocky Linux 8 system up and running, and that you are logged in as a user with sudo privileges.
Install the ssh-keygen
utility
The first step in setting up SSH keys is to install the ssh-keygen
utility. This utility is used to generate the SSH keys, and is included in the openssh-server
package. To install this package, run the following command:
sudo yum install openssh-server
Generate the SSH keys
Once the ssh-keygen
utility is installed, you can generate the SSH keys by running the following command:
ssh-keygen
This will start the key generation process, and will prompt you for a few pieces of information. First, it will ask you where you want to save the key. It’s recommended to use the default location, which is ~/.ssh/id_rsa
. Next, it will ask you to enter a passphrase for the key. This is an optional security measure that adds an extra layer of protection for your SSH key. If you choose to use a passphrase, make sure to remember it, as you will need it every time you use the SSH key to log in to a remote system.
Once you have entered the necessary information, the ssh-keygen
utility will generate the SSH key pair, which consists of a private key (id_rsa
) and a public key (id_rsa.pub
). These keys will be saved in the location you specified in the previous step.
Copy the public key to the remote system
Now that you have generated the SSH keys, the next step is to copy the public key to the remote system that you want to log in to. This is typically done using the ssh-copy-id
utility, which is included in the openssh-clients
package. To install this package, run the following command:
sudo yum install openssh-clients
Once the ssh-copy-id
utility is installed, you can copy the public key to the remote system by running the following command:
ssh-copy-id user@remote-system-ip-address
Replace user
with the username on the remote system, and remote-system-ip-address
with the IP address of the remote system. This command will copy the public key to the ~/.ssh/authorized_keys
file on the remote system, which allows you to use the SSH key to log in to the remote system.
Test the SSH key login
Once the public key has been copied to the remote system, you can test the SSH key login by running the following command:
ssh user@remote-system-ip-address
Replace user
with the username on the remote system, and remote-system-ip-address
with the IP address of the remote system. If the SSH key login is successful, you should be logged in to the remote system without being prompted for a password. This indicates that the SSH key has been set up correctly and is working as expected.
If you encounter any issues or errors during the SSH key setup process, you can refer to the documentation for the ssh-keygen
and ssh-copy-id
utilities, as well as the sshd
service, for troubleshooting tips and additional information.
In conclusion, setting up SSH keys on Rocky Linux 8 is a simple and secure way of logging in to a remote Linux system. By following the steps outlined in this article, you can easily generate and configure SSH keys to enable passwordless login to your remote Linux systems.