Linux安全加固脚本

Linux安全
1447
linux
linux 举报
2020-06-04
#安全加固脚本
#!/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


倒序看帖 只看楼主
热点关注
You need Perl 5 安装openssl时报错提示需要安装perl 5
shell 脚本中常见的 if [ $? -ne 0 ]; 意思
shell 中 if [ “x${var}“ == “x“ ] 中 x的作用
shell脚本每行后面多了一个^M的原因和解决办法
服务停止、启动、重启一体化脚本,万能语言启动脚本
shell参数判断
在后台用进程名运行bash脚本
shell脚本每行后面多了一个^M的原因和解决办法
定时检测服务,检测down掉后重启。系统检测到DMSERVER运行正常
挂载磁盘的时候遇到一个问题,挂载完磁盘之后重启服务器挂载的盘丢失了.
中标麒麟系统Your trial is EXPIRED and no VALID licens
termux 开启ssh并用用户名和密码登陆
extman-1.1自带了图形化显示日志的功能;此功能需要rrdtool的支持,您需要安装此些模块才可能正常显示图形日志。
postfix的相关个别参数设置
postfix中recipient/client/sender/helo四者的区别