What I want to do:
- I want to make an SSH connection and log in to Linux, which was created using Azure, as a user named testuser.
Problem:
- I get the following error when I run the ssh command.
C:Usersavduser>ssh testuser@<IP address>
testuser@<IP address>: Permission denied(publickey).
- /var/log/auth.log
Connection reset by authenticating user testuser <IP address> port <portNum> [preauth]
**I tried: **
- change
/etc/ssh/sshd_config
PasswordAuthentication yes
- service restart:
systemctl restart sshd
- virtial Machine restart:
reboot
I don’t have any other ideas to try.
Thank you
2
Answers
I also had to change in /etc/ssh/sshd_config
Thank you.
Given the steps you’ve already taken and the persistent issue, let’s explore additional solutions and troubleshooting steps to resolve the
Permission denied (publickey)
error when trying to SSH into your Linux VM in Azure astestuser
. I feel it has something to do with the pem keys. However better to verify all the other aspects as well.Open
/etc/ssh/sshd_config
and confirm there’s only onePasswordAuthentication yes
directive and it’s not commented out. After making changes, remember to restart the SSH service (sudo systemctl restart sshd
). Ensure thetestuser
exists and has a valid password set. Having said that.In order to login to a linux machine on azure there are two ways-
Using SSH-
Create your Linux VM as usual on Azure.
Just select SSH public key. As go proceed, Azure will prompt you to download this pem key which you just created. Download and save it to your desired location and continue to complete the setup process. Once the VM is ready, go to resource and connect.
Post validation, it will ask you to connect. Now it’s your choice if you want to connect via azure cli or your own native ssh for example powershell. Here just do
ssh -i ~/<yourpath-where-you-downloaded-the-pemfile>/<Your-Key-Name.pem> <username>@20.127.229.58
Second option, using password.
Same process as above just during creation select password instead of ssh and give your preferred password.
Rest of the configuration will remain same, but here azure won’t prompt you for downloading the pem key as you have set password. Just connect once the system is ready.
Do a
su <username>
Reference:
MS Doc