配置普通用户有使用sudo命令的权限

在linux系统中,新建用户并没有执行sudo权限,如新建一个AAA的用户,输入sudo命令会有如下提示:

  aaa is not in the sudoers file.  This incident will be reported.

这句的意思是在sudoers文件中不存在aaa这个用户,这个时间会被报告给管理员。
 既然知道问题处于sudoers这个文件,那我们就看看这个文件为何方神圣:

 [root@dbs aaa]# vi /etc/sudoers
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.
## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2
## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem

输入i,对文件进行编辑,发现底部有只读提示:

-- INSERT -- W10: Warning: Changing a readonly file

应该是没有权限,退出编辑状态后查看权限:

[root@dbs aaa]# ll /etc/sudoers
-r--r-----. 1 root root 3825 Jul 22 01:05 /etc/sudoers

原来root也只有只读权限,难怪,首先修改权限以让root有完全控制权限:

[root@dbs aaa]#chmod 740 /etc/sudoers

再次编辑,这次没有出现只读提示了,找到如下字段:

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
oracle  ALL=(ALL)       ALL
aaa     ALL=(ALL)       ALL

添加aaa用户,添加后如aaa  ALL=(ALL)       ALL

修改完后输入:wq保存,保存后记得把权限修改回去,否则会有错误提示

#chmod 440 /etc/sudoers

权限一定是440,否则就会有错误提示。

OK,在aaa用户下就可以正常使用sudo命令咯。

其实可以直接使用visudo命令编辑该文件,还不存在权限问题

你可能感兴趣的:(Linux)