aws lightsail新建了机子,系统是ubunt22,用了下面的脚本,本以为可以直接root用户直接登录机子,结果登录ssh的时候,报错。No supported authentication methods available server sent:publickey
#!/bin/bash
echo root:NRSFTjBt8pxZSqX9 |sudo chpasswd root
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo reboot

网上找了下原因,先看看ssh状态,确定机子是安装了ssh的。

然后查看机子/etc/ssh/下面的sshd_config文件,下图显示白色的2个地方也设置了,按说可以直接ssh登录的,为啥还是不行呢。

还有个地方需要修改下才可以。
root@ip-172-26-5-146:/etc/ssh# cd sshd_config.d
root@ip-172-26-5-146:/etc/ssh/sshd_config.d# ls
60-cloudimg-settings.conf
root@ip-172-26-5-146:/etc/ssh/sshd_config.d#
nano 60-cloudimg-settings.conf

把里面的PasswordAuthentication no改成PasswordAuthentication yes
然后,重启ssh服务。
systemctl restart sshd
做完上面的操作,就可以用root用户直接登录ubuntu22了
