Linux创建root权限用户、禁用root登录

ゝ一世哀愁。 2022-04-06 10:23 474阅读 0赞

欢迎访问我的个人博客网站:http://www.yanmin99.com/

一、创建root权限用户步骤

  • 1、创建用户yanmin

    • A、adduser yanmin

      1. //创建用户
      2. [root@iZrj98p4hhys0y9fdxmcy4Z ~]# adduser yanmin
    • B、设置用户密码

      1. //输入两次密码
      2. [root@iZrj98p4hhys0y9fdxmcy4Z ~]# passwd yanmin
      3. Changing password for user yanmin.
      4. New password:
      5. Retype new password:
      6. passwd: all authentication tokens updated successfully
  • 2、赋予yanmin用户root权限

    • A、第一种方案:修改/etc/sudoers文件,找到下面一行,在root下面添加一行

      1. # User privilege specification
      2. root ALL=(ALL:ALL) ALL
      3. yanmin ALL=(ALL:ALL) ALL
    • B、第二种方案:修改/etc/passwd文件,找到如下行,把用户ID修改为0,如下:

      1. yanmin:x:0:1000:yanmin,,,:/home/yanmin:/bin/bash
  • 3、测试用户yanmin登录

    1. ssh yanmin@xx.xx.xx.xx
  • 4、如果想免密码登陆,请参考

    • Linux使用公钥ssh登录

二、禁用root登录步骤

  • 1、准备工作

    • 注意:禁用root登陆之前,一定要确认其他用户可以登录,并且具备root权限
  • 2、把/etc/ssh/sshd_config中(PermitRootLogin no)设置YES

    1. PermitRootLogin yes修改为
    2. PermitRootLogin no
  • 3、重启SSH daemon服务

    1. //centos
    2. /etc/init.d/sshd restart
    3. //ubuntu
    4. //如果ssh重启没有效果,就重启系统
    5. /etc/init.d/ssh restart
    6. shutdown -r now
  • 4、尝试远程登陆

    1. yanmin:~ yanmin$ ssh root@gitlab
    2. root@gitlab's password: Permission denied, please try again.

发表评论

表情:
评论列表 (有 0 条评论,474人围观)

还没有评论,来说两句吧...

相关阅读