Ubuntu禁止密码登录无效
# Ubuntu配置禁止密码登录无效
# 问题:
Ubuntu20.04禁用密码登录,使用密钥登陆。本来是十分简单的操作,但是ssh配置一直不生效。再三检查ssh配置文件都没有任何问题。
# 原因:
在ssh配置文件中,默认导入sshd_config.d
文件夹下的所有conf
配置。
Include /etc/ssh/sshd_config.d/*.conf
在ubntu中默认生成50-cloud-init.conf
,在sshd_config.d
文件夹下
taketo@ubunt:~$ ll /etc/ssh/sshd_config.d/
total 12
drwxr-xr-x 2 root root 4096 Aug 11 08:55 ./
drwxr-xr-x 4 root root 4096 Aug 11 12:19 ../
-rw------- 1 root root 27 Aug 11 08:55 50-cloud-init.conf
taketo@ubunt:~$ sudo cat /etc/ssh/sshd_config.d/50-cloud-init.conf
PasswordAuthentication yes
# 解决方案
删除50-cloud-init.conf
文件或者在50-cloud-init.conf
配置文件中配置禁止密码登陆参数。
taketo@ubunt:~$ sudo cat /etc/ssh/sshd_config.d/50-cloud-init.conf
PasswordAuthentication no
PubkeyAuthentication yes
# 重启ssh服务
taketo@ubunt:~$ systemctl restart ssh
上次更新: 2023/12/14, 12:05:09