linux下禁止root远程登录

一、添加和root权限一样的用户

   1、

    adduser admin

    passwd  admin (修改密码)

 2、修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示

  • vim /etc/sudoers 
  • ## Allow root to run any commands anywhere
  • root ALL=(ALL) ALL
  • admin ALL=(ALL) ALL

二、禁止root远程登录

需要编辑/etc/ssh/sshd_config。

vim /etc/ssh/sshd_config    找到 PermitRootLogin

改为 PermitRootLogin no

重启  service sshd restart

你只是禁止了root用户登陆,没有禁止别的用户,先用别的用户登陆,在 su root 切回root用户

切换到root用户还要在输如密码

原文地址:https://www.cnblogs.com/hellohero55/p/12085060.html