云服务器修改默认 root 登录

一些云厂商,例如 AWS 和 Azure,默认禁止 Root 登录,需要 admin 登陆后,再执行 sudo su root 来提权,以保障安全。

运行如下脚本即可一键解决此类问题。

 

sudo su root
cd
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
sed -i 's/.*\(ssh-ed25519 .*\)/\1/' ~/.ssh/authorized_keys
# 你也有可能用的是ssh-rsa,那么就把上面的ssh-ed25519改成ssh-rsa
# sed -i 's/.*\(ssh-rsa .*\)/\1/' ~/.ssh/authorized_keys

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.