如何在 Linux/Unix 中使用 sudo 授予普通用户 root 权限

在CentOS/Red Hat Linux上使用sudo赋予其他用户超级管理员权限:

方法1

# visudo
# Add an extra line in the last and make this entry
jack    ALL=(ALL)   ALL

使用上面的这一行,告诉 Linux 系统在所有主机和所有命令上为用户 jack 授予完全权限

[jack@test ~]$sudo /etc/init.d/network restart
[sudo] password for test:
Shutting down interface eth0:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1
                                                           [  OK  ]

方法2

将用户添加到wheel组

# usermod -G wheel jack

检查:

# cat /etc/group | grep wheel
wheel:x:10:root,jack

现在在 sudoers 文件中取消注释这一行

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

我们这样做的原因是因为默认 root 是 wheel 组的成员,所以如果我们想向任何普通用户授予 root 级别权限,然后将他/她添加到 wheel 组中。

$sudo /etc/init.d/vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
日期:2020-06-02 22:16:59 来源:oir作者:oir