AWS Lightsail 开启root登陆权限(User data),也可适用于EC2, GCP, AZURE等

此文转自于:
https://moeclub.org/2017/07/14/327/?spm=82.8
谢谢V佬

将下面代码中的第一句中的Vicer改为自己将要设置的密码. 否则默认root密码为Vicer.
创建instance时,点击add launch script,将下列代码复制进去(注意更改root密码).

#!/bin/bash
echo root:Vicer |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登陆.
以上代码在Debian/Ubuntu上通过测试. 其他发行版自行测试.

点赞

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注