sudo,用其他用户的身份执行命令。
运行该命令时,系统首先检查/etc/sudoers,判断该用户是否有执行sudo的权限,在确定有执行权限后,要求输入自己的密码(当前用户),如果密码正确,会以root用户的身份运行后面的命令。
出现xxx is not in the sudoers file. This incident will be reported.
一般是提示xxx用户没有执行sudo的权限。
使用visudo
命令编辑配置文件,用PgDn
翻到大概倒数十几行的位置,复制root那一行,修改成对应的用户,并粘贴。
NOPASSWD
表示执行sudo时不再额外输入当前用户的密码,特别注意不是NOPASSWORD,不然保存的时候会报错。:wq!
保存并退出,以普通用户登陆并执行命令,不会再提示错误了。
ps:xxx用户相关操作
添加用户:useradd xxx
设置用户密码:passwd xxx
删除用户:userdel xxx
查看用户:users
、who
、w
三个都可以