How to configure SSH keys in Ubuntu 22.04/Debian 10
Introduction
SSH is a secure network protocol used for the remote management of servers. It is a secure way to connect to a server and perform operations on it without the need to be physically present at the server. SSH keys are used to authenticate to a remote server instead of password-based authentication. In this manual, we will explain how to configure SSH keys in Ubuntu 22.04/Debian 10.
Step 1: Install the SSH client
Before continuing, make sure you have the SSH client installed on your local machine. If you have not installed it yet, open a terminal and run the following command:
sudo apt-get install ssh
Step 2: Generate an SSH key
To generate an SSH key, open a terminal and run the following command:
ssh-keygen
This will start the process of generating an SSH key. The command will ask you to specify a location to save the SSH key. If you do not specify a location, it will be saved in the default directory ~/.ssh/id_rsa. You can also specify a comment for the SSH key.
After providing the location and the comment, the command will prompt you to provide a passphrase. You can leave it blank for passwordless authentication.
The ssh-keygen command will generate two files: one private and one public. The private file will be saved in the location you specified previously and the public file will be saved in the same directory with the .pub extension.
Step 3: Copy the public key to the remote server
Once the SSH key has been generated, you must copy the public key to the remote server. To do this, run the following command:
ssh-copy-id user@remote-server
Replace user with your username on the remote server and remote-server with the IP address or the domain name of the server.
The command will copy the public key to the authorized_keys file in the ~/.ssh directory on the remote server. If this file does not exist, the command will create it automatically.
Step 4: Authenticate to the remote server
Once the public key has been copied to the remote server, you can authenticate to the remote server without the need to provide a password. To do this, run the following command:
ssh user@remote-server
Replace user with your username on the remote server and remote-server with the IP address or the domain name of the server.
This command will start an SSH connection to the remote server and will use the public key to authenticate.
Conclusion
In this manual, we have explained how to configure SSH keys in Ubuntu 22.04/Debian 10. Generating an SSH key and copying it to the remote server is a secure and efficient way to authenticate to a remote server, without the need to provide a password.