Centos/Ubuntu/Debian 快速切换root登录

今天在使用阿里云的时候,重装了一下centos6.8的系统,然后发现通过VNC可以正常登录,root密码正确的情况下通过SSH登录一直提示错误,通过百度后发现是SSH登录未开启,但是在VNC模式下不太方便使用VIM编辑的,因此如何快速一键快速开启SSH登录呢,因此才有了一下脚本,记录以作后续需求。

echo root:自定义密码 |sudo chpasswd root    //改动作未修改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 sed -i 's/^.*RSAAuthentication.*/RSAAuthentication yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^.*PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config;
sudo reboot