Linux⽤户权限及⽇志审计管理
1、账户管理
uradd
-e 账户终⽌⽇期少年的勇气
-g ⽤户登⼊起始⽤户组
-s ⽤户登录的shell命令
-M 不建⽴家⽬录
-u ⽤户的ID值
urdel
passwd
金凯瑞的经典电影change #修改⽤户密码有效期
urmod #修改⽤户的命令
id #查看⽤户的UID/GID及所属的⽤户组
visudo #配置sudo权限的编辑命令。/etc/sudoers,推荐visudo来操作(会⾃动检查语法)。
su #切换⽤户
groupadd #添加⽤户组
groups #显⽰⽤户所属组
echo "123456“|paassword --stdin utest #密码修改
passwd -l urtest #锁定⽤户urtest,使之不能更改密码
w,who,last,lastlog,urs,groups,id #⽤户查询相关命令
2、⽤户权限管理
qq电脑登录(1)运维组
初级运维查看系统信息,及⽹络状态
/usr/bin/free,/usr/bin/iostat,/usr/bin/top,/bin/hostname,/sbin/ifconfig,/bin/netstat,/sbin/route
⾼级运维查看系统信息,查看和修改⽹络配置,进程管理,软件包管理,存储管理
/usr/bin/free,/usr/bin/iostat,/usr/bin/top,/bin/hostname,/sbin/ifconfig,/bin/netstat,/sbi
n/route,/sbin/iptables,/etc/init.d/network,/bin/nice,/bin/kill,/usr/bin/kill,/usr/bin/killal,/bin/rpm,/usr/bin/up2date,/usr/bin/yum,/sbin/fdisk,/sbin/parted,/sbin/partpro be,/bin/umount
运维经理超级⽤户权限
ALL
(2)开发组
初级开发 root的查看权限,对应服务查看⽇志的权限
/usr/bin/tail/app/log*,/bin/grep/app/log*/,/bin/cat,/bin/ls
⾼级开发
/sbin/rvice,/sbin/chkconfig,tail/app/log*,grep/app/log*,/bin/cat,/bin/ls
开发经理
ALL,/usr/bin/passwd[A-Za-z]*,!/usr/bin/passwd,!/usr/sbin/visudo,!/usr/bin/vi*sudoer*
demo
1)创建6个⽤户
[root@jackroo ~]# for ur in chuji001 chuji002 chuji003 net001 nior001 manager001
> do
> uradd $ur
> echo "111111"|passwd --stdin $ur
> done
Changing password for ur chuji001.
新年祝福语简短8字
passwd: all authentication tokens updated successfully.
Changing password for ur chuji002.
passwd: all authentication tokens updated successfully.
Changing password for ur chuji003.
passwd: all authentication tokens updated successfully.
Changing password for ur net001.
passwd: all authentication tokens updated successfully.
Changing password for ur nior001.
passwd: all authentication tokens updated successfully.
Changing password for ur manager001.
passwd: all authentication tokens updated successfully.
成语大全四个字
[root@jackroo ~]# tail -6 /etc/passwd
chuji001:x:505:505::/home/chuji001:/bin/bash
chuji002:x:506:506::/home/chuji002:/bin/bash
chuji003:x:507:507::/home/chuji003:/bin/bash
net001:x:508:508::/home/net001:/bin/bash
nior001:x:509:509::/home/nior001:/bin/bash
manager001:x:510:510::/home/manager001:/bin/bash
2)sudoer配置内容
[root@test ~]# cat /etc/sudoers
## Sudoers allows particular urs to run various commands as
## the root ur, without needing the root password.
##该⽂件允许特定⽤户像root⽤户⼀样使⽤各种各样的命令,⽽不需要root⽤户的密码##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## urs or groups.
## 在⽂件的底部提供了很多相关命令的⽰例以供选择,这些⽰例都可以被特定⽤户或## ## ⽤户组所使⽤
## This file must be edited with the 'visudo' command.
## 该⽂件必须使⽤"visudo"命令编辑
## Host Alias
#主机别名
操老师## Groups of machines. You may prefer to u hostnames (perhap using
## wildcards for entire domains) or IP address instead.
## 对于⼀组服务器,你可能会更喜欢使⽤主机名(可能是全域名的通配符)
## 或IP地址代替,这时可以配置主机别名
# Host_Alias FILESERVERS = fs1, fs2
# Host_Alias MAILSERVERS = smtp, smtp2
## Ur Alias
#⽤户别名
## The aren't often necessary, as you can u regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just u %groupname
## rather than USERALIAS
## 这并不很常⽤,因为你可以通过使⽤组来代替⼀组⽤户的别名
# Ur_Alias ADMINS = jsmith, mikem
## Command Alias
## The are groups of
## 指定⼀系列相互关联的命令(当然可以是⼀个)的别名,通过赋予该别名sudo权限,## 可以通过sudo调⽤所有别名包含的命令,下⾯是⼀些⽰例
春心荡漾## Networking
#⽹络操作相关命令别名
Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient,
/usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig,
/sbin/mii-tool
## Installation and management of software
#软件安装管理相关命令别名
Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
## Services
#服务相关命令别名
Cmnd_Alias SERVICES = /sbin/rvice, /sbin/chkconfig
## Updating the locate databa
#本地数据库升级命令别名
Cmnd_Alias LOCATE = /usr/sbin/updatedb
## Storage
#磁盘操作相关命令别名
#磁盘操作相关命令别名
Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount
## Delegating permissions
#代理权限相关命令别名
Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
## Process
#进程相关命令别名
Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
## Drivers
#驱动命令别名
Cmnd_Alias DRIVERS = /sbin/modprobe
#环境变量的相关配置
# Defaults specification
#
# Disable "ssh hostname sudo <cmd>", becau it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
Defaults requiretty
Defaults env_ret
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
_XKB_CHARSET XAUTHORITY"
## Next comes the main part: which urs can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## 下⾯是规则配置:什么⽤户在哪台服务器上可以执⾏哪些命令(sudoers⽂件可以在多个系统上共享)
## Syntax:
##语法
## ur MACHINE=COMMANDS
## ⽤户登录的主机=(可以变换的⾝份)可以执⾏的命令
##
## The COMMANDS ction may have other options added to it.
## 命令部分可以附带⼀些其它的选项
##
## Allow root to run any commands anywhere
## 允许root⽤户执⾏任意路径下的任意命令
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## rvice management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## 允许sys中户组中的⽤户使⽤NETWORKING等所有别名中配置的命令
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
## 允许wheel⽤户组中的⽤户执⾏所有命令
## Same thing without a password
## 允许wheel⽤户组中的⽤户在不输⼊该⽤户的密码的情况下使⽤所有命令
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the urs group to mount and unmount the
## cdrom as root
## 允许urs⽤户组中的⽤户像root⽤户⼀样使⽤mount、unmount、chrom命令
# %urs ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the urs group to shutdown this system
# %urs localhost=/sbin/shutdown -h now
## 允许urs⽤户组中的⽤户像root⽤户⼀样使⽤shutdown命令
3、服务器⽇志审计项⽬提出及实施
1. 实施对所有⽤户⽇志记录⽅案;
2)通过sudo和syslog配合实现对所有⽤户进⾏⽇志审计并将记录集中管理;
3)实施后让所有运维和开发的所有执⾏的命令都有记录可查,杜绝了内部⼈员的操作安全隐患。
解决⽅案:
sudo配合syslog服务,进⾏⽇志审计
1)安装sudo命令,syslog服务(centos6.4为rsyslog服务);
[root@jackroo data]# rpm -qa|egrep "sudo|syslog"
sudo-1.8.6p3-12.el6.x86_64
rsyslog-5.8.10-8.el6.x86_64
yum install sudo syslog -y
2)配置sudoers
[root@jackroo data]# echo "Defaults logfile=/var/log/sudo.log">>/etc/sudoers
[root@jackroo data]# tail -1 /etc/sudoers
Defaults logfile=/var/log/sudo.log
#检查语法
[root@jackroo data]# visudo -c
/etc/sudoers: pard OK
[root@jackroo data]# echo "local2.debug /var/log/sudo.log">>/f
3)重启⽇志服务
[root@jackroo data]# /etc/init.d/rsyslog restart
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
[root@jackroo data]# ll /var/log/sudo.log
-
rw------- 1 root root 0 Nov 19 12:30 /var/log/sudo.log
4)测试
[studyboy@jackroo root]$ sudo uradd dddd
[studyboy@jackroo root]$ cat /var/log/sudo.log
cat: /var/log/sudo.log: Permission denied
[studyboy@jackroo root]$ sudo su -
[root@jackroo ~]# cat /var/log/sudo.log
Nov 19 12:32:37 : studyboy : TTY=pts/0 ; PWD=/root ; USER=root ;
COMMAND=/usr/sbin/uradd dddd
Nov 19 12:33:06 : studyboy : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/su
5)集中管理
echo "*.info @logrver">>/f #将info⽇志推送到⽇志服务器
⽇志审计⽅法:
1.创建⽤户审计⽂件存放⽬录和审计⽇志⽂件 ;
mkdir -p /var/log/urmonitor/
2.创建⽤户审计⽇志⽂件;
3.将⽇志⽂件所有者赋予⼀个最低权限的⽤户;
chown nobody:nobody /var/log/urmonitor/urmonitor.log
4.给该⽇志⽂件赋予所有⼈的写权限;同性黄文
chmod 002 /var/log/urmonitor/urmonitor.log
5.设置⽂件权限,使所有⽤户对该⽂件只有追加权限 ;
chattr +a /var/log/urmonitor/urmonitor.log
6.编辑vim /etc/profile⽂件,添加如下脚本命令;
export HISTORY_FILE=/var/log/urmonitor/urmonitor.log
export PROMPT_COMMAND='{ date "+%y-%m-%d %T > $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(whoami) #### $(history 1 | { read x cmd ; echo "$cmd"; })"; } >>$HISTORY_FILE'7.使配置⽣效
source /etc/profile
审计时查看/var/log/urmonitor/urmonitor.log⽂件即可,它会记录登上服务器所有⽤户使⽤的命令。为了更安全,还可以将改⽂件打包压缩,ftp⾄其它本地。