Password Login Belongs to the Past with Public Key Authentication
Public key authentication is an easier and more reliable method to connect to the Secure Shell Server SSH compared to the old- fashioned password-based login. Keys are basically less prone to brute-force attacks.
If you want to force users to use keys add the line in the /etc/sshd/sshd_config at the SSH server.
The command above will force SSH key based authorization. The authentication keys, called SSH keys, are created using the
keygen program. At the next step each user would generate on their local computers key pairs using the ssh-keygen -t rsa command. There are other algorithms as well as keys sizes you might want to change.
Copying the Public Key to the Server
Then they should copy the content of their public keys from id_rsa.pub into ~/.ssh/authorized_keys on the server they want to login. The users can copy the public key to the server manually or they can utilize the another tool from the ssh package: ssh-copy-id. The setup assumes that the user kept to the rsa algorithm.
$ ssh-copy-id -i ~/.ssh/id_rsa.pub remoteuser@remotehost