第21章 軟件安裝:源代碼與 Tarball 練習題

情景模擬題

請依照下面的方式來創建你係統的重要文件校驗值,並每日進行比對。

  1. 將 /etc/{passwd,shadow,group} 以及系統上面所有的 SUID/SGID 文件建立文件列表,該列表文件名爲 important.file
ls /etc/{passwd,shadow,group} > important.file
find /usr/sbin /usr/bin -perm /6000 >> important.file
  1. 通過這個文件名列表,以名爲 md5.checkfile.sh 的文件名去建立校驗值,並將該校驗值文件 finger1.file 設置成不可修改的屬性
vim md5.checkfile.sh
#! /bin/bash
for filename in $ (cat important.file)
do 
	md5sum $filename >> finger1.file
done

sh md5.checkfile.sh
chattr +i finger1.file
  1. 通過相同的機制去建立後續的分析數據爲 finger_new.file,並將兩者進行比對,若有問題則發生 email 給 root :
vim md5.checkfile.sh
#! /bin/bash
if ["$1" == "new"]; then
	for filename in $ (cat important.file)
	do 
		md5sum $filename >> finger1.file
	done
	echo "New file finger1.file is created."
	exit 0
fi
if [! -f finger1.file]; then
	echo "file: finger1.file NOT exist."
	exit 1
fi

[-f finger_new.file] && rm finger_new.file
for filename in $ (cat important.file)
do 
	md5sum $filename >> finger1.file
done

testing = $(diff finger1.file finger_new.file)
if ["$testing" != ""]; then
	diff finger1.file finger_new.file | mail -s 'finger trouble..' root
fi

vim /etc/crontab
30 2 * * * cd/root; sh md5.checkfile.sh
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章