背景
在使用linux系统时,经常会遇到需要修改用户权限为root权限。通过修改用户所属群组groupid为root,此操作只能使普通用户实现享有部分root权限,普通用户仍不能像root用户一样享有超级权限,依旧影响操作。
下文将详细介绍,linux更改用户权限为root权限的几种方法。
创建用户
1、使用adduser命令创建一个普通用户test:
adduser test #添加一个名为test的用户
passwd test #修改用户test的密码
Changing password for user test.
New UNIX password: #在这里输入新密码
Retype new UNIX password: #再次输入新密码
passwd: all authentication tokens updated successfully.
给普通用户赋予root权限
方法一: 通过修改 /etc/sudoers 文件内容来实现
1、找到下面一行,把前面的注释(#)去掉,如下图:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
2、修改用户test所属群组,使其属于root组,命令如下:
usermod -g root test
方法二: 通过对 /etc/sudoers 文件添加内容来实现
在文件中找到下面一行,在其后添加一行“test ALL=(ALL) ALL”,如下图:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
test ALL=(ALL) ALL
方法三: 通过修改 /etc/passwd 文件中用户ID来实现(注:该方法简单粗暴,不建议采纳,若方法一、二使用后权限仍不满足,再使用该方法)
1、在文件中找到下面一行,如下所示:
test:x:500:500:test:/home/test:/bin/bash
2、将其内容修改为如下并保存:
test:x:0
:500:test:/home/test:/bin/bash #0表示用户ID修改为0