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 -
Login to your existing azure VM using passwords authentication.
Create new ssh key pair.
ssh-keygen -t rsa -b 2048
Replace
~/.ssh/authorized_keys
with~/.ssh/id_rsa.pub
keymv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
Save
~/.ssh/id_rsa
public key to your local system.Edit
/etc/ssh/sshd_config
and make following changesChange PasswordAuthentication to this:
PasswordAuthentication no
Change PubkeyAuthentication to this:
PubkeyAuthentication yes
Change PermitRootLogin to this:
PermitRootLogin no
Change ChallengeResponseAuthentication to this:
ChallengeResponseAuthentication no
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:
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