A-A+

CentOS添加Root权限(超级用户)的方法

2015年08月11日 Linux 暂无评论 阅读 4,853 views 次

1、添加普通用户

[root@server ~]# useradd dupeng       //添加一个名为dupeng的用户

[root@server ~]# passwd dupeng       //修改dupeng用户的密码

 

2、赋予root权限

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

## Allows people in group wheel to run all commands

# %wheel    ALL=(ALL)     ALL

修改为:

#Allows people in group wheel to run all commands

 %wheel     ALL=(ALL)     ALL

把dupeng修改为属于root用户组

[root@server ~]# usermod -g root dupeng

修改完毕后,登录dupeng账户,然后用“su -”命令切换,即可获得root用户权限进行操作。

 

方法2):修改/etc/sudoers文件,找到下面一行,在root下面添加一行

##Allow root to run any commands anywhere

root    ALL=(ALL)    ALL

添加一行

##Allow root to run any commands anywhere

root    ALL=(ALL)    ALL

dupeng    ALL=(ALL)    ALL

 

修改后,用dupeng帐号登录,然后用"su -"命令即可获得root权限

 

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

dupeng:x:500:500::/home/dupeng:/bin/bash

修改为

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

修改完毕,用dupeng账户登录,直接获取的就是root帐号的权限。

 

 


【su命令详解】

这个命令非常重要,他可以使一个一般用户拥有root用户或其他用户的权限,也可以使root用户以一般用户的身份做些事情。但一般用户使用该命令的时候必须有所切换账户的口令。如果要退出当前用户的登录可以用exit命令。

su作用:

su的作用是更改为其他用户的身份,需要对应用户密码(超级用户除外)

 

标签:

给我留言