溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)下如何實(shí)現(xiàn)用戶審計(jì)

發(fā)布時(shí)間:2021-09-27 09:35:47 來源:億速云 閱讀:141 作者:iii 欄目:系統(tǒng)運(yùn)維

這篇文章主要講解了“Linux系統(tǒng)下如何實(shí)現(xiàn)用戶審計(jì)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linux系統(tǒng)下如何實(shí)現(xiàn)用戶審計(jì)”吧!

創(chuàng)建審計(jì)日志目錄
 

代碼如下:

mkdir -p /var/log/user_audit

創(chuàng)建用戶審計(jì)日志文件;
 

代碼如下:

touch /var/log/user_audit/user_audit.log

將文件賦予低權(quán)限用戶
 

代碼如下:

chown nobody:nobody /var/log/user_audit/user_audit.log

賦予所有人寫權(quán)限
 

代碼如下:

chmod 002 /var/log/user_audit/user_audit.log

賦予所有用戶追加權(quán)限
 

代碼如下:

chattr +a /var/log/user_audit.log

編輯/etc/profile 增加以下內(nèi)容;
 

代碼如下:

export HISTORY_FILE=/var/log/user_audit/user_audit.log
export PROMPT_COMMAND='{ date "+%y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}")

實(shí)例
多人共同使用的服務(wù)器權(quán)限確實(shí)不好管理,誤操作等造成故障,無法追究,最好的辦法就是將用戶操作實(shí)時(shí)記錄到日志,并推送到遠(yuǎn)程日志服務(wù)器上。包括(用戶登陸時(shí)間,目錄,操作命令及時(shí)間戳等)。以便事后追查。
環(huán)境:centos5.5 X86_64 2臺(tái)              #備注:把兩臺(tái)主機(jī)的防火墻和selinux關(guān)閉。在進(jìn)行操作。
(一)日志服務(wù)器IP:10.0.2.164
(二)客戶端服務(wù)器IP:10.0.2.165
1.先在日志服務(wù)器10.0.2.164主機(jī)上操作:

代碼如下:

[root@MySQL-B ~]# echo "*.info    /var/log/client" >> /etc/syslog.conf
#配置日志保存文件,把該文件第一行的*.info 提出來。單獨(dú)放一行。
[root@MySQL-B ~]# service syslog restart                                #重啟syslog日志服務(wù)。
Shutting down kernel logger: [  OK  ]
Shutting down system logger: [  OK  ]
Starting system logger: [  OK  ]
Starting kernel logger: [  OK  ]
[root@MySQL-B ~]# vim /etc/sysconfig/syslog                             #接收客戶端寫入。


把SYSLOGD_OPTIONS="-m 0"  更改為:SYSLOGD_OPTIONS="-m 1 -r"
2.然后在客戶端服務(wù)器10.0.2.165主機(jī)上操作:

代碼如下:

[root@MySQL-A ~]# vim /etc/profile                                      #添加如下行。
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
[root@MySQL-A ~]# source /etc/profile                                   #重新手動(dòng)source更新。


2.1.客戶機(jī)修改日志服務(wù)器10.0.2.165主機(jī)上操作:

代碼如下:

[root@MySQL-A ~]# echo "10.0.2.164 logserver" >> /etc/hosts             #日志服務(wù)器地址。
[root@MySQL-A ~]# echo "*.info   @logserver" >> /etc/syslog.conf      
#將info日志推送到日志服務(wù)器,把該文件第一行的*.info 提出來。單獨(dú)放一行。
[root@MySQL-A ~]# /etc/init.d/syslog restart                            #重啟syslog日志。
Shutting down kernel logger: [  OK  ]
Shutting down system logger: [  OK  ]
Starting system logger: [  OK  ]
Starting kernel logger: [  OK  ]


3.測試,在客戶端主機(jī)上10.0.2.165主機(jī)上測試并操作:                     

代碼如下:

[root@MySQL-A ~]# test
[root@MySQL-A ~]# echo "this is a test 1"
this is a test 1
[root@MySQL-A ~]# echo "this is a test 2"
this is a test 2
[root@MySQL-A ~]# echo "this is a test 3"
this is a test 3
[root@MySQL-A ~]# echo "this is a test 4"
this is a test 4
[root@MySQL-A ~]# echo "this is a test 5"
this is a test 5


4.返回日志服務(wù)器10.0.2.164主機(jī)上看結(jié)果,是否記錄下來客戶端主機(jī)執(zhí)行的操作?

代碼如下:

[root@MySQL-B ~]# cat /var/log/client
Apr  6 10:37:55 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test1"
Apr  6 10:37:59 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test2"
Apr  6 10:38:01 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test3"
Apr  6 10:38:04 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test4"
Apr  6 10:38:06 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test5"


返回參數(shù)分別為:#操作時(shí)間  #操作IP  #有效用戶  #實(shí)際登陸時(shí)間  #路徑  #使用的命令

感謝各位的閱讀,以上就是“Linux系統(tǒng)下如何實(shí)現(xiàn)用戶審計(jì)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Linux系統(tǒng)下如何實(shí)現(xiàn)用戶審計(jì)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI