Solved

Enable SSH key login and disable password login

I created a centos vps and since i created that on phone, I enabled password login and did not specify any ssh key.


Now I am trying to update the config in /etc/ssh/sshd_config to disable password login and enable key based login but the config changes are not getting reflected. I am not able to login with public key.


I added a user with sudo permission. for that user, I added the key in .ssh/authorized_keys file. but ssh user@ip always asks for password.


Can someone please suggest on this what I am doing wrong or is sshd config not updatable once vps is created?

  • To answer your question, once the VPS is created with password authentication only, if you want to manually allow key authentication, you may do so. We do not restrict this. As a suggestion I've included a helpful link and outlined some steps below:


    I have successfully followed this guide to configure SSH key login:


    https://www.liberiangeek.net/2014/07/enable-ssh-key-logon-disable-password-password-less-logon-centos/


    The steps are:

     1. Generate public key on client machine 

    ssh-keygen -t rsa


    2. Copy public key from client (~/.ssh/id_rsa.pub) to server machine (~/.ssh/authorized_keys):

    cat ~/.ssh/id_rsa.pub | ssh root@Server_IP_Address "cat >> ~/.ssh/authorized_keys"


    3. On server, edit /etc/ssh/sshd_config to enable key auth and disable password auth. Uncomment and modify below lines as shown:

    PubkeyAuthentication yes
    AuthorizedKeyFile  .ssh/authorized_keys
    PasswordAuthentication no
    ChallengeResponseAuthentication no


    4.  Reload SSHD on server:

    service sshd reload


Login or Signup to post a comment