今天就跟大家聊聊有關Linux安全加固腳本的示例分析,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
#安全加固腳本
#!/bin/bash
#version1.0;write at 2017-03-29;
#write by Ringoo;
#1.將root管理員名稱修改為Ringoo
useradd -u 0 -g 0 -o ringoo
useradd pso
#2.修改默認密碼策略
#備份文件
cp /etc/login.defs /etc/login.defs.bak
sed -i 's/99999/90/' /etc/login.defs
#3.設置3次輸錯密碼鎖定用戶
#備份文件
cp /etc/pam.d/system-auth /etc/pam.d/system-auth.bak
sed -e '5 i\auth required /lib64/security/pam_tally2.so deny=3 unlock_time=300' -i /etc/pam.d/system-auth
#密碼復雜度設置
sed -e "14 i\password requisite pam_cracklib.so minlen=10 difok=3 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1 try_first_pass retry=3" -i /etc/pam.d/system-auth
sed -e '15d' -i /etc/pam.d/system-auth
#修改/etc/profile
#備份文件
cp /etc/profile /etc/profile.bak
sed -e 's/HISTSIZE=1000/HISTSIZE=3000/' -i /etc/profile
sed -i "/HISTSIZE=3000/a HISTTIMEFORMAT=\"%F %T \"" /etc/profile
sed -i "/HISTSIZE=3000/a TMOUT=1800" /etc/profile
sed -i "$ a\export HISTORY_FILE=/var/log/useraudit.log" /etc/profile
sed -i "$ a\export PROMPT_COMMAND=\'{ h=\`history 1\`;w=\`who am i\`;echo -e \$(date \"+%Y-%m-%d %H:%M:%S\") --- \$w ---\$h;} >> \$HISTORY_FILE\'" /etc/profile
/bin/touch /var/log/useraudit.log
/bin/chmod 777 /var/log/useraudit.log
/usr/bin/chattr +a /var/log/useraudit.log
#修改sshd配置
#備份文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sed -e 's/\#PermitRootLogin yes/PermitRootLogin no/' -i /etc/ssh/sshd_config
sed -e 's/\#Port 22/Port 2222/' -i /etc/ssh/sshd_config
sed -e 's/\#UseDNS yes/UseDNS no/' -i /etc/ssh/sshd_config
sed -e 's/X11Forwarding yes/X11Forwarding no/' -i /etc/ssh/sshd_config
sed -e 's/GSSAPIAuthentication yes/\#GSSAPIAuthentication yes/' -i /etc/ssh/sshd_config
sed -e 's/GSSAPICleanupCredentials yes/\#GSSAPICleanupCredentials yes/' -i /etc/ssh/sshd_config
#/etc/init.d/sshd restart
#禁用不需要的服務
/sbin/chkconfig ip6tables off
/sbin/chkconfig iptables off
/sbin/chkconfig avahi-daemon off
/sbin/chkconfig avahi-dnsconfd off
#數據庫服務器這里請酌情配置
#備份文件
#cp /etc/pam.d/login /etc/pam.d/login.bak
#cp /etc/security/limits.conf /etc/security/limits.conf.bak
#sed -i "$ a\session required /lib64/security/pam_limits.so" /etc/pam.d/login
#sed -i "$ a\* soft nofile 65535" /etc/security/limits.conf
#sed -i "$ a\* hard nofile 65535" /etc/security/limits.conf
echo "please restart the server for the settings to take effect,press enter exit"
read pause
exit 1看完上述內容,你們對Linux安全加固腳本的示例分析有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。