基於安全的考量,在預設的狀況下創建 AWS Lightsail 實例時,會調整實例的 SSH 相關設定;將其設置為啟用 SSH 連線,並自動生成 SSH 公鑰與私鑰。
這樣的方式能夠免除一些暴力破解密碼的惡意連線,但對部分使用者來說稍嫌不方便,因為需要下載 SSH 私鑰並在客戶端設置。
因此我們可以在創建 AWS Lightsail 實例時,添加啟動腳本來替 root
使用者創建密碼:
Bash
echo root:custompassword | 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 service sshd restart