Use ssh-keys for secured logging and file transfer

  1. Create RSA key pair1,2 by typing the below command in terminal
     ssh-keygen -t rsa -b 4096
    

  2. Store the keys and passphrase. To use default path press enter button on keyboard
     Enter file in which to save the key (/home/user/.ssh/id_rsa):
    
     Enter passphrase (empty for no passphrase):
    

  3. Copying public key to remote server
     ssh-copy-id -i ~/.ssh/id_rsa user@remotehost    
    

Following the above steps should allow the user to login to a remote server without entering any password except the passpharse used to set the ssh keys. Sometimes there could be instances where the user will be prompted to enter the password even after following the above steps. In such cases, the user has to login to the remote server and change the permissions of the .ssh directory in their home directory.

    chmod 700 ~/.ssh 

References:

  1. https://www.ssh.com/ssh/keygen/
  2. https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys–2