Authenticate via SSH without password
Recovering old and very useful tutorials for those of us who play with servers, we are going to review how to create SSH keys so as not to have to write the password when authenticating against the server.
First we must be clear about what we are going to do, since applying this configuration would imply that a malicious user with access to your console could access the remote machine. It is not advisable to do this with the root user, but rather with one with few privileges to avoid scares.
The process is as simple as first creating a public key, which will be the one we will use to authenticate ourselves.
# ssh-keygen -t rsa
Next, it will ask us for the place where it will store the key, which we can save by default in /home/user/.ssh/id_rsa and the passphrase, and I say phrase and not word, because something that we always have to keep in mind is that the more digits in the passwords, the passphrase, …. the better, how much space we have to put characters.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/usuario/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/usuario/.ssh/id_rsa.
Your public key has been saved in /home/usuario/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx user@computer
The key’s randomart image is:
+–[ RSA 2048]—-+
| |
| |
| . .|
| = + + o.|
| . * . + |
| or = + |
| . . |
+—————–+
And now we only have to copy the password to the machine to which we want to give that access.
# ssh-copy-id -i ~/.ssh/id_rsa.pub remoteuser@remotamachine
From this moment we can enter via SSH without having to write the password, either ourselves or a process that we put in the Cron, for example.