Adding SSH Keys

Posted on Jul 3, 2017, 4:01 PM

Follow these steps to add SSH Keys:

  1. Generate private/public RSA key pair using:
    ssh-keygen -t rsa
    
    You can use the defaults. The private key will be at ~/.ssh/id_rsa and the public at ~/.ssh/id_rsa.pub.
  2. Copy the public key to the server using:
    scp ~/.ssh/id_rsa.pub <username>@<host>:<filepath>/id_rsa.pub
    
  3. Login to the server using:
    ssh <username>@<host>
    
  4. Add the public key to the host using:
    cat <filepath>/id_rsa.pub >> ~/.ssh/authorized_keys
    
    In case of error try changing the file permission:
    chmod 700 ~/.ssh/authorized_keys
    

And... Done!