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

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

相关文章

nmcli 配置网络
ESXI虚拟机磁盘扩容
openwrt usb热插拔 u盘或移动硬盘热插自动挂载
openwrt 移动硬盘开机挂载失效解决
Ubuntu 22.04 安装 Wireguard
Linux 使用rsync快速删除海量文件目录

发布评论