记一次ssh禁止密码登陆配置经历

在这篇文章里,我记录一下我最近一次配置ssh禁止密码登陆的经历。我本来打算实现禁止通过ssh密码登陆我的mac笔记本,但是却多次尝试无果,究其原因,是过于自以为是了,以为只要配置了PasswordAuthentication no就可以了,但是实际上还需要配置 KbdInteractiveAuthentication no,明明上面的注释

1
2
3
4
5
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PermitEmptyPasswords no
# Change to no to disable s/key passwords
KbdInteractiveAuthentication no

就写了但是还是没有注意到,还有一个原因是太相信ai了,最开始ai的解释是PasswordAuthentication no就是配置ssh禁止密码登陆的配置,最后看了网上许多教程和自己反复确认之后,终于明白了,就是要同时配置这两个选项,下面是我最终成功配置的步骤。(中间一步都不能少,内容最好不要改,改了可能就又失败了)。
先修改/etc/ssh/sshd_config文件 添加上面的配置,然后重启ssh服务打开设置,然后在共享里面关闭远程登录,然后重新开启远程登录,最后用另一台机器测试ssh登陆,就可以发现已经成功禁止密码登陆了。