0

I have Ubuntu 22.04.2 LTS installed as a virtual machine (Windows Hyper-V). I am making the following changes to /etc/ssh/sshd_config

PermitRootLogin prohibit-password
PubkeyAuthentication yes
PubkeyAcceptedKeyTypes=+ssh-rsa
PasswordAuthentication no
ChallengeResponseAuthentication no

After the changes are made sudo sshd -t throws no errors.

I have tried many options (list below) to restart/reload sshd service:

sudo service sshd restart
sudo systemctl restart sshd.service
sudo service sshd reload
sudo systemctl reload sshd.service
sudo kill -SIGHUP $(pgrep -f "sshd -D")

but regardless of the command (or even if I execute all of them) I am still able to log into virtual machine providing password only. Even after reebot I can log into virtual machine.

For clarification the virtual machine is running on ip 172.30.42.222 while WSL from which I am login in runs on 172.30.32.1

2 Answers2

2

It seems that the problem was solved. I have commented one line in

/etc/ssh/sshd_config.d/50-cloud-init.conf

and of course the line was

PasswordAuthentication yes

First uncommented line in /etc/ssh/sshd_config is Include /etc/ssh/sshd_config.d/*.conf which indicates that the file /etc/ssh/sshd_config.d/50-cloud-init.conf is included into sshd_config. However the line PasswordAuthentication no is sshd_config comes after the Include... line which suggest that the latter line should be valid.

Can anyone comment on that issue?

1

I solved using this answer https://askubuntu.com/a/1440509/1713168

Inside the directory /etc/ssh/sshd_config.d/ there is only one .conf file (50-cloud-init.conf), but inside it contains the line: PasswordAuthentication yes

I changed the line to #PasswordAuthentication no

and i restarted the ssh. Now is working. I can only access with the ssh key.