简体   繁体   中英

Change Azure VM authentication to ssh key

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

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

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:

在此处输入图像描述

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

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

在此处输入图像描述

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

在此处输入图像描述

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

PasswordAuthentication no

在此处输入图像描述

PubkeyAuthentication yes

在此处输入图像描述PermitRootLogin no

在此处输入图像描述

ChallengeResponseAuthentication no

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM