1.切换到 root 用户下
su root
2.添加sudo文件的写权限
chmod u+w /etc/sudoers
3.编辑sudoers文件
vi /etc/sudoers
找到root ALL=(ALL) ALL,在下面添加usernameALL=(ALL) ALL
在sudoers中可以添加下面任意一条记录youuserALL=(ALL) ALL%youuserALL=(ALL) ALLyouuserALL=(ALL) NOPASSWD: ALL%youuserALL=(ALL) NOPASSWD: ALL第一行:允许用户youuser执行sudo命令(需要输入密码)第二行:允许用户组youuser里面的用户执行sudo命令(需要输入密码)第三行:允许用户youuser执行sudo命令,不需要输入密码第四行:允许用户组youuser里面的用户执行sudo命令(需要输入密码)
4.撤销sudoers文件写权限,命令:
chmod u-w /etc/sudoers