233 字
1 分钟
开启root登录权限
脚本介绍
将下面代码中的第一句中的vcQGwH79I70dLRzS改为自己将要设置的密码。
否则默认 root 密码为vcQGwH79I70dLRzS
#切换到rootsudo -i#从$变成#即为切换到root脚本
创建 instance 时,点击 add launch script,将下列代码复制进去(注意更改 root 密码).
#!/bin/bashecho root:vcQGwH79I70dLRzS sudo chpasswd rootsudo 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脚本-开启 root 密码登录
sed -i 's/^.*PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;service sshd restart;/etc/init.d/ssh restart;备注
对于 EC2,GCE 等机器也可以使用。
不能添加代码的机器,可以登录进 ssh,再执行上面的代码。
也可以开启 root 登录。
以上代码在 Debian/Ubuntu 上通过测试。
其他发行版自行测试。
其他
在有些机器上开启后登录依然提示,是因为没有删除密钥前面的判断
vim /root/.ssh/authorized_keys删除在 ssh-rsa 前面的全部内容,然后保存重启