注意:此项操作也可适用于EC2, GCP, AZURE等
将下面代码中的第一句中的xcaaaa改为自己将要设置的密码,否则默认root密码为xcaaaa
创建instance时,点击add launch script,将下列代码复制进去(注意更改root密码)
echo root:xcaaaa |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
对于EC2,GCE等机器也可以使用,不能添加代码的机器,可以登录进ssh,再执行上面的代码,也可以开启root登陆
以上代码在Centos/Debian/Ubuntu上通过测试, 其他发行版自行测试
详情:https://moeclub.org/2017/07/14/327/