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

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

一、创建root权限用户步骤
  • 1、创建用户yanmin

    • A、adduser yanmin

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

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

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

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

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

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

二、禁用root登录步骤
  • 1、准备工作

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

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

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

    yanmin:~ yanmin$ ssh root@gitlab
    root@gitlab's password:
    Permission denied, please try again.
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值