Linux下不同运维人员共用root 账户权限审计

Linux下不同运维人员共用root 账户权限审计

  在中小型企业,公司不同运维人员基本都是以root 账户进行服务器的登陆管理,缺少了账户权限审计制度。不出问题还好,出了问题,就很难找出源头。

  这里介绍下,如何利用编译bash 使不同的客户端在使用root 登陆服务器使,记录各自的操作,并且可以在结合ELK 日志分析系统,来收集登陆操作日志

二、环境

  服务器:CentOS 6.5、Development tools、使用密钥认证,SElinux 关闭。

  客户端:生成密钥对,用于登录服务器 (2台)

三、搭建部署 (服务器操作 192.168.30.72)

3.1 下载编译bash

[root@open1 ~]# wget http://ftp.gnu.org/gnu/bash/bash-4.1.tar.gz [root@open1 ~]# tar xvf bash-4.1.tar.gz [root@open1 ~]# cd bash-4.1

3.2 先修改下 config-top.c文件,大概94行、104行,由于c 语言中 注释是/**/ ,所以不要删除错了。修改如下:

[root@open1 bash-4.1]# vim config-top.c #define SSH_SOURCE_BASHRC #define SYSLOG_HISTORY

3.3 修改下bashhist.c 文件,让终端上的命令记录到系统messages 中,并且以指定的格式。并传入获得的变量。修改后的内容如下:

[root@open1 bash-4.1]# vim bashhist.c #... 省略部分段落 void bash_syslog_history (line) const char *line; { char trunc[SYSLOG_MAXLEN]; const char *p; p = getenv("NAME_OF_KEY"); if (strlen(line) < SYSLOG_MAXLEN) syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d PPID=%d SID=%d User=%s USER=%s CMD=%s", getpid(), getppid(), getsid(getpid()), current_user.user_name, p, line); else { strncpy (trunc, line, SYSLOG_MAXLEN); trunc[SYSLOG_MAXLEN - 1] = ' '; syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d PPID=%d SID=%d User=%s USER=%s CMD=%s", getpid(), getppid(), getsid(getpid()), current_user.user_name, p, trunc); } }

3.4 配置安装路径,编译安装,编译到/usr/local/目录下。

[root@open1 bash-4.1]# ./configure --prefix=/usr/local/bash_new [root@open1 bash-4.1]# make && make install ... if test "bash" = "gettext-tools"; then \ /bin/sh /root/bash-4.1/./support/mkinstalldirs /usr/local/bash_new/share/gettext/po; \ for file in Makefile.in.in remove-potcdate.sin quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot Makevars.template; do \ /usr/bin/install -c -m 644 ./$file \ /usr/local/bash_new/share/gettext/po/$file; \ done; \ for file in Makevars; do \ rm -f /usr/local/bash_new/share/gettext/po/$file; \ done; \ else \ : ; \ fi make[1]: Leaving directory `/root/bash-4.1/po'

编译完成后,将新的bash 追加到 /etc/shells 中,并修改root用户的登陆shell 环境为新编译的shell。如下

[root@open1 bash-4.1]# echo "/usr/local/bash_new/bin/bash" >> /etc/shells [root@open1 bash-4.1]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /usr/local/bash_new/bin/bash

 

[root@open1 bash-4.1]# vim /etc/passwd root:x:0:0:root:/root:/usr/local/bash_new/bin/bash

注销当前root用户,重新登陆后,查看/var/log/messages,如下就可以看到记录了操作命令

四、SSH客户端生成密钥部分

4.1 在client1上(192.168.30.99)操作,用户zhangsan

Linux下不同运维人员共用root 账户权限审计

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/15006.html