Linux 用户添加sudo权限

时间:2022-03-19 02:41:55

本文简单介绍下在Linux环境下如何创建一个用户并给此用户赋予sudo权限。


1 root创建测试用户test

[root@ha-4 ~]# useradd test


2 切换test用户检查sudo权限

[root@ha-4 ~]# su - test
[test@ha-4 ~]$ sudo date

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

3 切换root用户用visudo添加test用户sudo权限

[root@ha-4 ~]# visudo
通过visudo打开/etc/sudoers文件,添加以下行并保存
test    ALL=(ALL)       NOPASSWD: ALL

4 再次切换test用户检查sudo权限

[root@ha-4 ~]# su - test
[test@ha-4 ~]$ sudo date
Fri Oct 28 11:19:57 CST 2016