由于管理的服务器不多,而且都是我一个人管,但公司发展越来越快,服务器也越来越多,人手也添加了,但不能一直都用root账号人手一份,为了安全和管理控制,决定部署sudo。sudo默认安装在系统里,配置日志文件跟踪的时候遇到问题,无论怎么操作,就是不能写入sudo日志。参考了网上的N多文章 ,都不能解决问题,其中的奥秘就在于他们都省略了一步。所以部署东西,最好还是先看官方文档为先,遇到小部份难题在google为好。

一、实验环境

  1. # cat /etc/redhat-release
  2. CentOS release 5.5 (Final)
  3. # rpm -qa | grep sudo
  4. sudo-1.7.2p1-5.el5
  5. [root@CentOS-A log]# rpm -ql  sudo
  6. /usr/share/doc/sudo-1.7.2p1/sample.sudoers
  7. /usr/share/doc/sudo-1.7.2p1/sample.syslog.conf

二、参考资料

注:留意我标明红色的地方,这些是成功配置所在。

  1. [root@CentOS-A ~]# cat /usr/share/doc/sudo-1.7.2p1/sample.sudoers
  2. #
  3. # Sample /etc/sudoers file.
  4. #
  5. # This file MUST be edited with the 'visudo' command as root.
  6. #
  7. # See the sudoers man page for the details on how to write a sudoers file.
  8. #
  9. # $Sudo: sample.sudoers,v 1.29 2008/10/03 19:55:57 millert Exp $
  10. ##
  11. # Override built-in defaults
  12. ##
  13. Defaults        syslog=auth
  14. Defaults>root       !set_logname
  15. Defaults:FULLTIMERS !lecture
  16. Defaults:millert    !authenticate
  17. Defaults@SERVERS    log_year, logfile=/var/log/sudo.log
  18. Defaults!PAGERS     noexec
  19. ##
  20. # User alias specification
  21. ##
  22. User_Alias  FULLTIMERS = millert, mikef, dowdy
  23. User_Alias  PARTTIMERS = bostley, jwfox, crawl
  24. User_Alias  WEBMASTERS = will, wendy, wim
  25. ##
  26. # Runas alias specification
  27. ##
  28. Runas_Alias OP = root, operator
  29. Runas_Alias DB = oracle, sybase
  30. ##
  31. # Host alias specification
  32. ##
  33. Host_Alias  SPARC = bigtime, eclipse, moet, anchor:\
  34. SGI = grolsch, dandelion, black:\
  35. ALPHA = widget, thalamus, foobar:\
  36. HPPA = boa, nag, python
  37. Host_Alias  CUNETS = 128.138.0.0/255.255.0.0
  38. Host_Alias  CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
  39. Host_Alias  SERVERS = master, mail, www, ns
  40. Host_Alias  CDROM = orion, perseus, hercules
  41. ##
  42. # Cmnd alias specification
  43. ##
  44. Cmnd_Alias  DUMPS = /usr/sbin/dump, /usr/sbin/rdump, /usr/sbin/restore, \
  45. /usr/sbin/rrestore, /usr/bin/mt
  46. Cmnd_Alias  KILL = /usr/bin/kill
  47. Cmnd_Alias  PRINTING = /usr/sbin/lpc, /usr/bin/lprm
  48. Cmnd_Alias  SHUTDOWN = /usr/sbin/shutdown
  49. Cmnd_Alias  HALT = /usr/sbin/halt
  50. Cmnd_Alias  REBOOT = /usr/sbin/reboot
  51. Cmnd_Alias  SHELLS = /sbin/sh, /usr/bin/sh, /usr/bin/csh, /usr/bin/ksh, \
  52. /usr/local/bin/tcsh, /usr/bin/rsh, \
  53. /usr/local/bin/zsh
  54. Cmnd_Alias  SU = /usr/bin/su
  55. Cmnd_Alias  VIPW = /usr/sbin/vipw, /usr/bin/passwd, /usr/bin/chsh, \
  56. /usr/bin/chfn
  57. Cmnd_Alias  PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less
  58. ##
  59. # User specification
  60. ##
  61. # root and users in group wheel can run anything on any machine as any user
  62. root        ALL = (ALL) ALL
  63. %wheel      ALL = (ALL) ALL
  64. # full time sysadmins can run anything on any machine without a password
  65. FULLTIMERS  ALL = NOPASSWD: ALL
  66. # part time sysadmins may run anything but need a password
  67. PARTTIMERS  ALLALL = ALL
  68. # jack may run anything on machines in CSNETS
  69. jack        CSNETS = ALL
  70. # lisa may run any command on any host in CUNETS (a class B network)
  71. lisa        CUNETS = ALL
  72. # operator may run maintenance commands and anything in /usr/oper/bin/
  73. operator    ALL = DUMPS, KILL, SHUTDOWN, HALT, REBOOT, PRINTING,\
  74. sudoedit /etc/printcap, /usr/oper/bin/
  75. # joe may su only to operator
  76. joe     ALL = /usr/bin/su operator
  77. # pete may change passwords for anyone but root on the hp snakes
  78. pete        HPPA = /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd root
  79. # bob may run anything on the sparc and sgi machines as any user
  80. # listed in the Runas_Alias "OP" (ie: root and operator)
  81. bob     SPARC = (OP) ALL : SGI = (OP) ALL
  82. # jim may run anything on machines in the biglab netgroup
  83. jim     +biglab = ALL
  84. # users in the secretaries netgroup need to help manage the printers
  85. # as well as add and remove users
  86. +secretaries    ALL = PRINTING, /usr/bin/adduser, /usr/bin/rmuser
  87. # fred can run commands as oracle or sybase without a password
  88. fred        ALL = (DB) NOPASSWD: ALL
  89. # on the alphas, john may su to anyone but root and flags are not allowed
  90. john        ALPHA = /usr/bin/su [!-]*, !/usr/bin/su *root*
  91. # jen can run anything on all machines except the ones
  92. # in the "SERVERS" Host_Alias
  93. jen     ALL, !SERVERS = ALL
  94. # jill can run any commands in the directory /usr/bin/, except for
  95. # those in the SU and SHELLS aliases.
  96. jill        SERVERS = /usr/bin/, !SU, !SHELLS
  97. # steve can run any command in the directory /usr/local/op_commands/
  98. # as user operator.
  99. steve       CSNETS = (operator) /usr/local/op_commands/
  100. # matt needs to be able to kill things on his workstation when
  101. # they get hung.
  102. matt        valkyrie = KILL
  103. # users in the WEBMASTERS User_Alias (will, wendy, and wim)
  104. # may run any command as user www (which owns the web pages)
  105. # or simply su to www.
  106. WEBMASTERS  www = (www) ALL, (root) /usr/bin/su www
  107. # anyone can mount/unmount a cd-rom on the machines in the CDROM alias
  108. ALL     CDROM = NOPASSWD: /sbin/umount /CDROM,\
  109. /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
  1. [root@CentOS-A ~]# cat /usr/share/doc/sudo-1.7.2p1/sample.syslog.conf
  2. # This is a sample syslog.conf fragment for use with Sudo.
  3. #
  4. # Sudo logs to local2 by default, but this is changable via the
  5. # --with-logfac configure option.  To see what syslog facility
  6. # a sudo binary uses, run `sudo -V' as *root*.  You may have
  7. # to check /usr/include/syslog.h to map the facility number to
  8. # a name.
  9. #
  10. # NOTES:
  11. #   The whitespace in the following line is made up of <TAB>
  12. #       characters, *not* spaces.  You cannot just cut and paste!
  13. #
  14. #   If you edit syslog.conf you need to send syslogd a HUP signal.
  15. #   Ie: kill -HUP process_id
  16. #
  17. #   Syslogd will not create new log files for you, you must first
  18. #   create the file before syslogd will log to it.  Eg.
  19. #   'touch /var/log/sudo'
  20. #
  21. # $Sudo: sample.syslog.conf,v 1.3 2004/10/01 14:58:15 millert Exp $
  22. # This logs successful and failed sudo attempts to the file /var/log/sudo
  23. local2.debug                    /var/log/sudo
  24. # To log to a remote machine, use something like the following,
  25. # where "loghost" is the name of the remote machine.
  26. local2.debug                    @loghost

三、完整配置

3.1.配置sudo日志文件

  1. #touch /var/log/sudo.log

3.2.修改/etc/syslog.conf配置文件

local2.debug                                  /var/log/sudo.log                     #空白处不能用空格键,必需用tab键

3.3、修改/etc/sudoers配置文件

注:不要手动修改配置文件 ,用visudo命令修改,好处是修改出错,保存会弹出错误提示信息,方便排错。

  1. #visudo
  2. efaults              logfile=/var/log/sudo.log  #添加这一行

3.4、重启syslog服务

  1. # ps -aux | grep syslog
  2. Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
  3. root     10367  0.0  0.1   1728   612 ?        Ss   23:10   0:00 syslogd -m 0
  4. root     10437  0.0  0.1   3920   688 pts/1    R+   23:41   0:00 grep syslog
  5. # kill -HUP 10367
  6. #/etc/init.d/syslog restart

四、成功测试

  1. # cat /var/log/sudo.log
  2. Dec 14 23:07:39 : firerat : TTY=pts/0 ; PWD=/home/firerat ; USER=root ;
  3. COMMAND=/bin/cat /etc/passwd

临高人社区:http://www.lingaoren.com

linux sudo log相关推荐

  1. linux sudo命令全称,linux sudo命令的概念与使用

    1.sudo介绍本文引用地址:http://www.eepw.com.cn/article/201610/305498.htm sudo是linux下常用的允许普通用户使用超级用户权限的工具,允许系统 ...

  2. Linux sudo命令的概念与使用

    1.sudo介绍 sudo是linux下常用的允许普通用户使用超级用户权限的工具,允许系统管理员让普通用户执行一些或者全部的root命令,如halt,reboot,su等等.这样不仅减少了root用户 ...

  3. linux sudo 权限_在Linux中使用sudo委派权限

    linux sudo 权限 我最近写了一个简短的Bash程序,将MP3文件从一个网络主机上的USB拇指驱动器复制到另一网络主机上. 这些文件被复制到我为志愿者组织运行的服务器上的特定目录中,从该目录可 ...

  4. Linux 新建log文件

    Linux 新建log文件 家目录下创建log文件(新文件) 在uwsgi.ini文件中添加 root : 家目录,新文件创建在那个目录下就写那个目录 logto = /root/uwsgi_log. ...

  5. linux sudo命令

    Linux sudo命令 正在上传-重新上传取消​ Linux 命令大全 Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行. 使用 ...

  6. linux用户的vim命令无效,Linux SUDO Bug可让您以root用户身份运行命令,大多数命令不受影响...

    已发现Linux sudo命令中的漏洞,该漏洞可能允许非特权用户以root用户身份执行命令.幸运的是,此漏洞仅在非标准配置中有效,并且大多数Linux服务器不受影响. 在获得此漏洞之前,重要的是要掌握 ...

  7. Linux sudo 被曝提权漏洞,任意用户均能以 root 身份运行命令

    Linux 用户请注意!根据外媒的报道,Linux sudo 被曝出存在一个提权漏洞,可完全绕过 sudo 的安全策略. 先简单说明一下情况,报道指出 sudo 存在一个安全策略隐患,即便" ...

  8. linux日志切割命令,Linux 服务器log日志切割三种方法【附命令行】

    今天爱分享给大家带来Linux 服务器log日志切割方法[三种附命令行],希望能够帮助到大家. 业务服务器上产生了一个 10G 的log文件,然后很悲催的是什么样的文本编辑器都打不开,然后只能切分一下 ...

  9. Linux查看log日志命令总结

    @Linux查看日志 Linux查看log日志命令总结 企业项目都运行在Linux环境,熟悉Linux环境下的日志查看结合远程调试端口及时排查程序bug,是后端程序员需掌握的必备技能. 1,动态实时查 ...

最新文章

  1. ruby中取反的问题
  2. 通过QUIC 0-RTT建立更快的连接
  3. 浅谈本地服务器的搭建 XAMPP
  4. java \t怎么从头开始_通过这些简单的步骤从头开始学习Java
  5. Win32ASM-进程学习【1】
  6. Hadoop框架:HDFS高可用环境配置
  7. python查找客户总金额_该程序查找需要支付给所有表现良好的Python的最低金额
  8. linux查看电脑硬件信息,Linux下查看电脑硬件配置【转】
  9. 【Python】SNMP的安装及Python的调用
  10. 迅雷精简版 Mac中文版
  11. 【f1c200s/f1c100s】PWM驱动适配
  12. 复制文件并重命名到新的文件夹
  13. PhotoScan软件进行无人机数据处理流程
  14. windows小工具txt转xlsx
  15. 性能监控——cpu使用率过高,该怎么分析?
  16. [附源码]计算机毕业设计springboot微信点餐系统
  17. 遇到的问题1:print时报错 can only concatenate str (not tuple) to str
  18. Android Studio实现内容丰富的旅游App
  19. 12306 火车票 Python爬虫 车次信息及经停站信息
  20. Raw与ProRes Raw

热门文章

  1. 项目0单节点的虚拟机做大数据开发(四万字全)
  2. 扬名立万影评爬取与分析
  3. 漫游测试之性能测试(5.5-查询设计)
  4. 免填邀请码解决方案,提高APP推广效率
  5. automake编译工程
  6. TF:TF定义两个变量相乘之placeholder先hold类似变量+feed_dict最后外界传入值
  7. perp系列之三:perp版本变化和作者联系方式
  8. 大学计算机英语怎么说,大学计算机是什么意思
  9. 做亚马逊的工作,到底辛不辛苦?值得吗?
  10. 两轮车新规实施,电池安全再上“紧箍咒”