一個Linux系統(tǒng)安全設(shè)置的Shell腳本的分享(適用CentOS)
我們將常用的系統(tǒng)安全配置制作為一個shell腳本,只需要在服務(wù)器上運(yùn)行這個shell腳本即可完成安全設(shè)置。
linux的系統(tǒng)安全設(shè) 置Shell腳本是第二次更新,已經(jīng)大量應(yīng)用在某大型媒體網(wǎng)站體系中,加入了之前沒有想到的一些安全設(shè)置。使用方法將其復(fù)制,保存為一個shell文件, 比如security.sh.將其上傳到Linux服務(wù)器上,執(zhí)行sh security.sh,就可以使用該腳本了!
# desc: setup linux system security
#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.sonauth required pam_tally.so onerr=fail deny=3 unlock_time=300nauth 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
- 一鍵配置CentOS iptables防火墻的Shell腳本分享
- Centos下IP與DNS設(shè)置方法詳解
- CentOS Linux服務(wù)器安全設(shè)置
- CentOS6.5設(shè)置Django開發(fā)環(huán)境
- Centos 6.5 服務(wù)器優(yōu)化配置備忘(一些基礎(chǔ)優(yōu)化和安全設(shè)置)
- centos最小化安裝系統(tǒng)后的基本調(diào)優(yōu)及安全設(shè)置
- centos 5.1下的安全設(shè)置(適合所有的linux版本)
- CentOS的圖形安裝及初始環(huán)境設(shè)置教程
- CentOS防火墻用法淺析
相關(guān)文章
getcwd cannot access parent directories錯誤解決方法
這篇文章主要介紹了getcwd cannot access parent directories錯誤解決方法,在Linux下執(zhí)行命令時有時會無意中遇到這個錯誤,這只是一個意外錯誤,解決方法很簡單,需要的朋友可以參考下2015-01-01Shell腳本調(diào)快調(diào)慢系統(tǒng)時間(測試服務(wù)器時使用)
這篇文章主要介紹了Shell腳本修改系統(tǒng)時間(測試服務(wù)器時使用),本文腳本用于調(diào)快或者調(diào)慢系統(tǒng)時間,需要的朋友可以參考下2014-12-12shell腳本通過expect實(shí)現(xiàn)自動單邊無密登錄功能
最近做項(xiàng)目需要實(shí)現(xiàn)單邊無密登錄功能,接下來小編給大家分享shell腳本通過expect實(shí)現(xiàn)自動單邊無密登錄功能,一起看看吧2017-01-01Shell兩種for循環(huán)對應(yīng)實(shí)現(xiàn)方法解析
這篇文章主要介紹了Shell兩種for循環(huán)對應(yīng)實(shí)現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-08-08shell腳本中執(zhí)行python腳本并接收其返回值的例子
這篇文章主要介紹了shell腳本中執(zhí)行python腳本并接收其返回值的例子,本文重點(diǎn)在于如何接收python腳本的返回值,需要的朋友可以參考下2014-08-08Linux Shell中curl和wget使用代理IP的方法教程
這篇文章主要給大家介紹了關(guān)于在Linux Shell中curl和wget使用代理IP的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08