切换到 root 用户

修改root的密码

  1. echo root:bad_password | sudo chpasswd root

使用以上命令完成 root 密码重置以后使用命令 su 登陆 root 用户, 再执行下面的命令

sshd 配置

开启 root 登录

  1. sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config

开启密码验证

  1. sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config

重启ssh服务

  1. service sshd restart

一次完成

  1. __main(){
  2. sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
  3. sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
  4. service sshd restart
  5. }
  6. __main