ubuntu一般用户执行 sudo 命令

By | 2018-11-27

在日常使用中有些情况下不能告知用户 root 的密码,这样就会导致用户无法使用例如: apt-get 等必须使用root权限执行的命令,管理员将会面临巨大的工作量,所以如果能让一般用户执行 sudo 命令就变成“必须”了。

在一般用户下执行sudo命令提示 xxxx is not in the sudoers file. This incident will be reported.

以下是解决方法:
1)先把 /etc/sudoers 更改为可写权限,默认为只读
#chmod u+w /etc/sudoers

2)编辑 sudoers
#vi sudoers

3)找出 “root ALL=(ALL) ALL” 这一行,在下面增加一新行
testuser  ALL=(ALL)ALL          <– testuser 是你增加root权限的系统用户

4)!wq 保存退出
5)把 sudoers 文件权限改回只读
#chmod u-w /etc/sudoers

这样 testuser 这个用户就可以执行必须 root 权限的命令了!

發佈留言