SSH to server without password

The requirement to ssh to server without password

To ssh without password, you must meet the condition:

  • Private key in client ~/.ssh/
  • Public key in server ~/.ssh/authorized_keys

Steps to setup

  1. Create ssh key pairs by ssh-keygen

    1
    2
    3
    4
    5
    6
    7
    # Generate key
    ssh-keygen

    # Check the generated key pair
    ls ~/.ssh
    -rw------- 1 sing staff 1679 Jun 8 2018 id_rsa
    -rw-r--r-- 1 sing staff 404 Jun 8 2018 id_rsa.pub
  2. Login to your server

  3. Copy the content of the publicKey (id_rsa.pub) to server’s ~/.ssh/authorized_keys

    1
    echo "${public key content}" >> ~/.ssh/authorized_keys
  4. Make sure the sshd setting /etc/ssh/sshd_config allow publickey authentication,

    1
    PubkeyAuthentication yes

    Restart by sudo systemctl restart ssh if you modify the sshd setting.

  5. Modify ssh config (~/.ssh/config) in your client to indicate which ssh key to use

    1
    2
    Host <server ip>
    IdentityFile ~/.ssh/id_rsa
  6. Verify ssh without password

    1
    ssh username@serverip