Configure SSH Key-Based Authentication on a Linux and Mac
How To Create SSH Keys
The first step to configure SSH key authentication to your server is to generate an SSH key pair on your local computer.
To do this, we can use a special utility called ssh-keygen, which is included with the standard OpenSSH suite of tools. By default, this will create a 2048 bit RSA key pair, which is fine for most uses.
On your local computer, generate a SSH key pair by typing:
ssh-keygen
The utility will prompt you to select a location for the keys that will be generated. By default, the keys will be stored in the ~/.ssh directory within your user’s home directory. The private key will be called id_rsa and the associated public key will be called id_rsa.pub. Stick with the default location.
Copying your Public Key Using SSH-Copy-ID
The easiest way to copy your public key to the server is to use a utility called ssh-copy-id. For this method to work, you must already have password-based SSH access to your server.
Simply specify the remote host that you would like to connect to and the user account that you have password SSH access to. This is the account where your public SSH key will be copied.
The syntax is:
ssh-copy-id username@remote_host
Special thanks to https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server