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

1
  • Welcome to the Ask Ubuntu community. This AskUbuntu thread may help resolve your issue.
    – richbl
    Commented May 7, 2023 at 3:34

2 Answers 2

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?

2
  • 1
    From man sshd_config: "For each keyword, the first obtained value will be used." Commented May 6, 2023 at 15:10
  • Thanks for clarification.
    – Jan Pips
    Commented May 6, 2023 at 15:14
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .