linux root权限的设置方法(实践)

发布时间:2018-04-24作者:laosun阅读(2278)

linux

    如果我们想要给某个用户分配root权限,那么怎么处理呢?

    方法一: 修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉

    ## Allows people in group wheel to run all commands
    %wheel    ALL=(ALL)    ALL

    然后修改用户,使其属于root组(wheel),命令如下:

    #usermod -g root sun

    修改完毕,现在可以用sun帐号登录,然后用命令 su - ,即可获得root权限进行操作。

    方法二: 修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

    ## Allow root to run any commands anywhere
    root    ALL=(ALL)     ALL
    sun     ALL=(ALL)     ALL

    修改完毕,现在可以用sun帐号登录,然后用命令 sudo  ,即可获得root权限进行操作。

    下边我们来做个测试

    [sun@CentOS_7 ~]$ sudo passwd sun002  #记住,一定要加 sudo,输入当前用户密码,即可给其他用户修改新密码
    [sudo] password for sun: 
    Changing password for user sun002.
    New password: 
    BAD PASSWORD: The password fails the dictionary check - it does not contain enough DIFFERENT characters
    Retype new password: 
    passwd: all authentication tokens updated successfully.


    方法三: 修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:

    tommy:x:500:500:tommy:/home/tommy:/bin/bash

    修改后如下

    tommy:x:0:500:tommy:/home/tommy:/bin/bash

    保存,用tommy账户登录后,直接获取的就是root帐号的权限。

    友情提醒:虽然方法三看上去简单方便,但一般不推荐使用,推荐使用方法二。

0 +1

版权声明

 linux

 请文明留言

0 条评论