Unix系统记录用户登录及操作日志配置——Solaris篇 C Shell
2020-6-3 16:48:25 Author: mp.weixin.qq.com(查看原文) 阅读量:6 收藏

Solaris下C shell包括tcsh和csh两个环境,以下分别描述。

C Shelltcsh


配置如下:

修改/etc/.cshrc文件(文件不存在创建即可):

vi /etc/.cshrc

在文件中加入以下内容,将其中的192.168.100.90替换为资源的IP

以上在记录登录日志的时候作了判断,保证了当用户使用tcsh命令切换shell的时候不会记录登录日志。

# Add content in /etc/.cshrc# Log C shell(tcsh) user login and commandhistoryset up_client_ip=`(who am i|cut -d\(-f2|cut -d\) -f1)`set up_flag=`echo $up_client_ip|awk -F '($1~/[0-9]+.[0-9]+.[0-9]+.[0-9]+/)'`if ( $up_flag == "" ) thenset -r up_client_ip=`grep"$up_client_ip" /etc/hosts|cut -f1`elseset -r up_client_ip=`(who am i|cut -d\(-f2|cut -d\) -f1)`endifset -r up_nowtime=`(date +"%Y-%m-%d%T")`if ( $user == `(id|cut -d\( -f2|cut -d\)-f1)` && "$0" == "tcsh" )  then               echo >/dev/null;      else               logger -p user.notice --class=\"HOST_LOGIN\" type=\"2\" time=\"$up_nowtime\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut-d\( -f2|cut -d\) -f1`\" operation=\"\" content=\"loginsuccessful\" authen_status=\"Success\" log_level=\"1\" session_id=\"$$\" >/dev/nullendifalias precmd 'logger -p user.notice --class=\"HOST_COMMAND\" type=\"3\" time=\"`date+"%Y-%m-%d %T"`\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut -d\( -f2|cut -d\) -f1`\" operation=\"`history 1 | cut -f3-`\" content=\"command\" authen_status=\"\" log_level=\"1\" session_id=\"$$\">/dev/null'
以上在记录登录日志的时候作了判断,保证了当用户使用tcsh命令切换shell的时候不会记录登录日志。

C Shellcsh

以下几点:

  • csh下使用了switch条件分支判断;
  • csh下用户的操作日志不能记录;

配置如下:

修改/etc/.login文件(文件不存在创建即可):

vi /etc/.login

在文件中加入以下内容,将其中的192.168.100.90替换为资源的IP

# Add content in /etc/.login# Log C shell(csh)user login and commandhistoryswitch ($shell) case */csh:      set up_nowtime=`date +"%Y-%m-%d %T"`      set up_client_ip=`(who am i|cut -d\( -f2|cut -d\) -f1)`      set up_flag=`echo $up_client_ip|awk -F '($1 ~/[0-9]+.[0-9]+.[0-9]+.[0-9]+/)'`      if ( $up_flag == "" ) then      set up_client_ip=`grep "$up_client_ip" /etc/hosts|cut -f1`      endif   logger -p user.notice -- class=\"HOST_LOGIN\"type=\"2\" time=\"$up_nowtime\" src_ip=\"$up_client_ip\" dst_ip=\"192.168.100.90\" primary_user=\"\" secondary_user=\"`id|cut -d\( -f2|cut -d\) -f1`\" operation=\"\" content=\"login successful\" authen_status=\"Success\" log_level=\"1\" session_id=\"$$\" >/dev/null   breaksw default:   breakswendsw
以上脚本判断了当前shell环境是否为csh,如果不做判断,对于tcsh环境来说,如果配置了上一节(/etc/.cshrc内容,tcsh的用户会发出两条日志记录。
switch的语法请参照solaris系统下的手册。

至此,Solaris下bash、sh、ksh、tcsh、csh环境下的登录日志、操作日志的配置方法已全部写完。后续发布:

  • Solaris系统下各个shell的启动文件;

  • Solaris下操作日志实现方法(PROMPT_COMMAND、trap、trap函数、precmd)的测试结果;


文章来源: https://mp.weixin.qq.com/s?__biz=MzI5NzAzMDg0NA==&mid=2650697982&idx=2&sn=4823abaaff3df9f4ef93b868f544fced&chksm=f4b1952dc3c61c3b9cd1518c47dd3ed5c1b02afb99021a6f36224e492c2cce29cfcb57140da3&scene=58&subscene=0#rd
如有侵权请联系:admin#unsafe.sh