Home > OS >  Change Azure VM authentication to ssh key
Change Azure VM authentication to ssh key

Time:12-21

I have Linux VM on Azure which at first set without SSH keys. which means authentication is made only with password via SSH. I would like to change it now. I tried the way I know, I can login with the keys - but still login with password.

What else did I miss? There is something else?

Thanks

Tried to configure SSH key, disable the 'passwordauthentication'

Change ssh config Add key via azure portal

CodePudding user response:

Try to following these steps -

  1. Login to your existing azure VM using passwords authentication.

  2. Create new ssh key pair.

    ssh-keygen -t rsa -b 2048

  3. Replace ~/.ssh/authorized_keys with ~/.ssh/id_rsa.pub key

    mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

  4. Save ~/.ssh/id_rsa public key to your local system.

  5. Edit /etc/ssh/sshd_config and make following changes

    Change PasswordAuthentication to this:

    PasswordAuthentication no

    Change PubkeyAuthentication to this:

    PubkeyAuthentication yes

    Change PermitRootLogin to this:

    PermitRootLogin no

    Change ChallengeResponseAuthentication to this:

    ChallengeResponseAuthentication no

  6. Restart the vm using following command

    sudo systemctl restart ssh

CodePudding user response:

I tried to reproduce the same in my environment and got the results like below:

I have created Linux VM on Azure first set without SSH keys only with password via SSH then I tried to authentication to ssh key like below:

Create SSH key pair:

ssh-keygen -t rsa -b 2048

Then, use /home/<user>/.ssh/id_rsa.pub

Enter passphrase: Give your password

Once you enter password RSA will executed successfully like below:

enter image description here

Then try to move to id_rsa to authorized using below script:

`mv/home/<user>/.ssh/id_rsa.pub/home/<user>/.ssh/authorized_keys`

enter image description here

when I run this cmd cat id_rsa I got public key successfully like below

enter image description here

I agree with schine som And save public key open config file with vi and try restart like below:

PasswordAuthentication no

enter image description here

PubkeyAuthentication yes

enter image description here PermitRootLogin no

enter image description here

ChallengeResponseAuthentication no

enter image description here

  • Related