Ubuntu 18 SSH禁用密码登陆失效

2024-08-12 309 0

禁用密码登陆但不生效

root@ecs-6537:/etc/cloud# cat /etc/ssh/sshd_config | grep PasswordAuthentication
PasswordAuthentication no

原因是被cloud-init影响了
解决:删除/etc/ssh/sshd_config.d/50-cloud-init.conf + 禁用或删除cloud-init

root@ecs-6537:/etc/cloud# grep -r "PasswordAuthentication" /etc/
/etc/ssh/sshd_config:PasswordAuthentication no
/etc/ssh/sshd_config:# PasswordAuthentication.  Depending on your PAM configuration,
/etc/ssh/sshd_config:# PAM authentication, then enable this but set PasswordAuthentication
/etc/ssh/sshd_config.ucf-dist:#PasswordAuthentication yes
/etc/ssh/sshd_config.ucf-dist:# PasswordAuthentication.  Depending on your PAM configuration,
/etc/ssh/sshd_config.ucf-dist:# PAM authentication, then enable this but set PasswordAuthentication
/etc/ssh/ssh_config:#   PasswordAuthentication yes
/etc/ssh/sshd_config.d/50-cloud-init.conf:PasswordAuthentication yes
root@ecs-6537:/etc/cloud# rm -rf /etc/ssh/sshd_config.d/50-cloud-init.conf 
root@ecs-6537:/etc/cloud# systemctl restart sshd

禁用或删除cloud-init
上面通过删除50-cloud-init.conf已经解决了 这里是防止下次重启又被初始化影响到

方法 1: 创建 /etc/cloud/cloud-init.disabled(重启后生效,删除该文件就可以恢复)

sudo touch /etc/cloud/cloud-init.disabled

方法 2: 彻底移除 cloud-init 软件包及文件夹

sudo apt purge cloud-init -y
sudo rm -rf /etc/cloud && sudo rm -rf /var/lib/cloud/

相关文章

Linux Sudo 权限配置
阿里云ECS云盘IOPS压测
nextcloud preview-generate 报错文件无权限解决
tcpdump 抓包使用小结
Linux Tcpdump抓包
Ubuntu 18.04 修复重启sysctl 失效

发布评论