Using a public/private key pair is more secure than using a password. You can configure your keypair to require a passphrase as well, adding a layer of security. The private key stays with you and the public key will then reside on the target host. The key will reside in the the appropriate user home directory under .ssh/authorized_keys
.
Creating a keypair is an easy task. All you are required to do is to do run the command ssh-keygen
. This utility will go ahead and out put the public/private keypair and ask if you wish to use a passphrase (if you do not wish to, you can simply press Enter without entering a phrase.
Once you have created your keypair you can then move on to copying it to the remote host. The command used for this is ssh-copy-id
.
ssh-keygen
/home/$USER/.ssh/id_rsa
)~/.ssh/id_rsa
file and the public key is written to the ~/.ssh/id_rsa.pub
file.ssh-copy-id <HOST>
to copy to the generated key to the target system (use IP or DNS address).If multiple users are using keys to log in to that specific account, the authorized_keys file may contain a lot of public keys. Make sure to never overwrite the file as it will wipe all keys which are being used by other users.