SSH is a secure network protocol used for remote server management. It is a secure way to connect to and perform operations on a server without the need to be physically present on 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 set up SSH keys on Ubuntu 22.04/Debian 10.
Before proceeding, make sure you have the SSH client installed on your local machine. If you haven't already installed it, open a terminal and run the following command:
sudo apt-get install ssh
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 prompt 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 comment, the command will prompt you to provide a password. You can leave it blank for passwordless authentication.
The ssh-keygen
command will generate two files: a private and a public file. The private file will be saved in the location you specified above and the public file will be saved in the same directory with the extension .pub
.
Once you have generated the SSH key, you must copy the public key to the remote server. To do this, run the following command:
ssh-copy-id usuario@servidor-remoto
Replace user
with your username on the remote server and remote-server
with the IP address or 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.
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 usuario@servidor-remoto
Replace user
with your username on the remote server and remote-server
with the IP address or domain name of the server.
This command will initiate an SSH connection to the remote server and use the public key to authenticate.
In this manual, we have explained how to set up SSH keys on 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.