First, create a public key from the computer that will connect to the host.
ssh-keygen -t rsa
Copy the public file to your account on the remote system.
#You can also do it manually
scp ~/.ssh/key.pub [email protected]:
Log-in to the remote system using a password
ssh [email protected]
Note: You may need to enable password-based authentication first. If you have access to the system, you can edit the
/etc/sshd_config
file.
Check if the ~/.ssh/authorized_keys
file exists, if it does not create it.
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
Add the contents of the public file to a new line on this file we just created.
#You can also do it manually with commands like vim or nano
cat key.pub >> ~/.ssh/authorized_keys
Check it has been added correctly
more ~/.ssh/authorized_keys
You now can delete the key.pub
file or move it to the .ssh
folder.
rm key.pub
If the key has the default name and is stored in the default directory, it will work automatically with a normal ssh connection.
If not, there are two ways to proceed.