1、创建用户
#adduser test
2、创建密码:
# passwd test
3、修改sudoers文件权限
[root@localhost /]# ll /etc/sudoers
-r--r-----. 1 root root 4328 9月 30 2020 /etc/sudoers
[root@localhost /]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
4、在sudoers文件中添加一行用户信息
[root@localhost /]# vi /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
test ALL=(ALL) ALL
5、保存文件,恢复;sudoers文件权限
[root@localhost /]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
tips:修改完成后,用户执行sudo后会提示输入密码,如果不想每次输入密码,将最后一个 ALL 修改成 NOPASSWD: ALL ,即
test ALL=(ALL) NOPASSWD: ALL