Solve ssh ban password login does not take effect
For safety concern, I will configure my ssh as follows:
1 | PubkeyAuthentication yes |
However, yesterday I find it does not work by mistake.
When I typed private key passphrase wrong 3 times, it pops password authentication to my surprise! Then I googled it and find the reason and solution.
Just login your server as root.
1 | cat /etc/ssh/sshd_config |
You will see this line:
1 | Include /etc/ssh/sshd_config.d/*.conf |
This means sshd_config will load configuration from other folder. And this has higher priority. Let’s see what is it.
1 | cd /etc/ssh/sshd_config.d/ |
You will see a file called “50-cloud-init.conf”
1 | cat 50-cloud-init.conf |
The output is:
1 | PasswordAuthentication yes |
This file is a default file in Ubuntu official image. Then you should know the reason why your “PasswordAuthentication no” cannot work. The solution is obvious. We can delete or edit this file.
1 | sudo rm 50-cloud-init.conf |
Then everything works fine.
It is highly recommended to check your server whether it contains 50-cloud-init.conf and whether ssh configure is correct and works as your expected.