环境:Ubuntu 12.04 server。
sudo权限分配使用visudo来管理。示例在/usr/share/doc/sudo/examples/sample.sudoers下有。
因为Ubuntu 12.04中使用的是rsyslog(Remote System Log),是syslog的升级版,但是使用方法跟syslog相同,在网上找到的很多资料都说修改/etc/syslog.conf文件(这是很多其他版本的linux和早期版本中ubuntu中用的),实际上修改/etc/rsyslog.conf是一样的。
1.配置/etc/rsyslog.conf
在其中加入一行:local2.debug /var/log/sudo.log(中间用tab分隔)
2.root用户执行visudo修改/etc/sudoers文件:
在其中添加:
##
# Override built-in defaults
##
Defaults syslog=auth
Defaults>ALL !set_logname
Defaults:FULLTIMERS !lecture
Defaults:millert !authenticate
Defaults@SERVERS log_year, logfile=/var/log/sudo.log
Defaults!PAGERS noexec
Defaults logfile=/var/log/sudo.log
3.重启rsyslog
service rsyslog restart
4.检验
可以看到在/var/log下面生成了sudo.log文件,对于错误的sudo操作的记录如下:
tsli@ubuntu:/usr/lib$ sudo ls
[sudo] password for tsli:
tsli is not in the sudoers file. This incident will be reported.
相关阅读:
Linux怎么添加用户成为sudoers http://www.linuxidc.com/Linux/2013-06/86098.htm
Linux基础——sudoers文件的写法 http://www.linuxidc.com/Linux/2013-06/85347.htm
定义Linux用户权限由你决定–sudo命令 http://www.linuxidc.com/Linux/2013-04/83580.htm
自动添加sudo权限脚本 http://www.linuxidc.com/Linux/2012-11/74471.htm
Linux配置sudo权限 http://www.linuxidc.com/Linux/2012-10/71795.htm
sudo配置临时取得root权限 http://www.linuxidc.com/Linux/2012-09/69525.htm
CentOS 系统sudo命令配置 http://www.linuxidc.com/Linux/2012-08/67841.htm
更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2