SSH as we know it, is a network protocol used to establish a secure connection between two machines (in most cases between a client and a server) and public key based and password authentication.
Check for existing SSH key pair
Before generating a new SSh key pair, check if you have and existing key pair on your client machine so you do not overwrite the existing key pair
ls -al ~/.ssh
if there are existing keys, you will files listed else you will see an empty directory listing.
Generate a new SSH key pair (if you don't have one)
Type in the following on the commandline to generate an SSH key pair with your email
$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
Press Enter to accept the default location and file name.
Copy the public key
To now login to your remote machine, you will have to copy the public key on the client to the remote machine. There are two ways to do this.
$ ssh-copy-id remote_username@remote_ip_address
You will be prompted to enter the
remote_username user password
$ remote_username@remote_ip_address's password:
Once the user is authenticated, the public key is copied to the remote machine's
authorized_keys file and the connection will be closed.
If ssh-copy-id utility is not available largely due to using Windows OS on the client machine you can use the method below
$ cat ~/.ssh/id_rsa.pub | ssh remote_username"cat >> ~/.ssh/authorized_keys"_ip_address
Try your password-less login
After the steps above the remote machine is ready for a password-less login. Lets try to login!
$ ssh remote_username@remote_ip_address
If everything goes well, your login should be successful.