Ubuntu 20 SSH 禁用密码登陆失效解决

2024-06-17 282 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/

相关文章

Rocky9 GitLab Docker 部署
USG6300 防火墙DNS 透明代理 指定域名解析为特定IP
关闭Ubuntu服务器systemd-resolved 53端口服务
Bind9 rpz 局部解析
服务器磁盘坏道检查
rocky9 nmcli 命令配置网络

发布评论