linux服務(wù)器安全加固shell腳本代碼
更新時(shí)間:2013年06月11日 15:05:34 作者:
有時(shí)候安裝完服務(wù)器以后,需要一些安全設(shè)置,這段腳本就是為了安全加固所寫,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
#!/bin/sh
# desc: setup linux system security
# author:coralzd
# powered by www.freebsdsystem.org
# version 0.1.2 written by 2011.05.03
#account setup
passwd -l xfs
passwd -l news
passwd -l nscd
passwd -l dbus
passwd -l vcsa
passwd -l games
passwd -l nobody
passwd -l avahi
passwd -l haldaemon
passwd -l gopher
passwd -l ftp
passwd -l mailnull
passwd -l pcap
passwd -l mail
passwd -l shutdown
passwd -l halt
passwd -l uucp
passwd -l operator
passwd -l sync
passwd -l adm
passwd -l lp
# chattr /etc/passwd /etc/shadow
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
# add continue input failure 3 ,passwd unlock time 5 minite
sed -i 's#auth required pam_env.so#auth required pam_env.so\nauth required pam_tally.so onerr=fail deny=3 unlock_time=300\nauth required /lib/security/$ISA/pam_tally.so onerr=fail deny=3 unlock_time=300#' /etc/pam.d/system-auth
# system timeout 5 minite auto logout
echo "TMOUT=300" >>/etc/profile
# will system save history command list to 10
sed -i "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile
# enable /etc/profile go!
source /etc/profile
# add syncookie enable /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies=1" >> /etc/sysctl.conf
sysctl -p # exec sysctl.conf enable
# optimizer sshd_config
sed -i "s/#MaxAuthTries 6/MaxAuthTries 6/" /etc/ssh/sshd_config
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
# limit chmod important commands
chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm
# history security
chattr +a /root/.bash_history
chattr +i /root/.bash_history
# write important command md5
cat > list << "EOF" &&
/bin/ping
/bin/finger
/usr/bin/who
/usr/bin/w
/usr/bin/locate
/usr/bin/whereis
/sbin/ifconfig
/bin/pico
/bin/vi
/usr/bin/vim
/usr/bin/which
/usr/bin/gcc
/usr/bin/make
/bin/rpm
EOF
for i in `cat list`
do
if [ ! -x $i ];then
echo "$i not found,no md5sum!"
else
md5sum $i >> /var/log/`hostname`.log
fi
done
rm -f list
您可能感興趣的文章:
相關(guān)文章
Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法
這篇文章主要介紹了Linux 中shell腳本設(shè)置開頭固定格式的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
shell中嵌套執(zhí)行expect命令實(shí)例
這篇文章主要介紹了shell中嵌套執(zhí)行expect命令實(shí)例,一直都想把expect的操作寫到bash腳本里,這樣就不用我再寫兩個(gè)腳本來執(zhí)行了,需要的朋友可以參考下2014-12-12
shell腳本echo輸出不換行功能增強(qiáng)實(shí)例
這個(gè)腳本很簡(jiǎn)單,就是可以用3種不同的函數(shù)(方法)來實(shí)現(xiàn),輸出后不換行2016-08-08
linux使用管道命令執(zhí)行ps獲取cpu與內(nèi)存占用率
這篇文章主要介紹了linux使用管道命令執(zhí)行ps獲取cpu與內(nèi)存占用率的示例,需要的朋友可以參考下2014-02-02
3000字掃盲shell基礎(chǔ)知識(shí)(新手必備)
這篇文章主要介紹了3000字掃盲shell基礎(chǔ)知識(shí),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2020-06-06

