aws lightsail新建了機(jī)子,系統(tǒng)是ubunt22,用了下面的腳本,本以為可以直接root用戶直接登錄機(jī)子,結(jié)果登錄ssh的時(shí)候,報(bào)錯(cuò)。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

網(wǎng)上找了下原因,先看看ssh狀態(tài),確定機(jī)子是安裝了ssh的。

然后查看機(jī)子/etc/ssh/下面的sshd_config文件,下圖顯示白色的2個(gè)地方也設(shè)置了,按說可以直接ssh登錄的,為啥還是不行呢。

還有個(gè)地方需要修改下才可以。
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服務(wù)。
systemctl restart sshd
做完上面的操作,就可以用root用戶直接登錄ubuntu22了
