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了
