#!/bin/bash# the files that need to be configured for backup cp /etc/login.defs /etc/login.defs.bakcp /etc/profile /etc/ profile.bakcp /etc/pam.d/common-password /etc/pam.d/common-password.baksed -i -e '/^ pass_max_days/' d /etc/login.defssed -i -e '/^pass_min_days/' d /etc/login.defssed -i -e '/^pass_warn_age/' d /etc/login.defs# prohibit combination key off sed -i -e '/^ca\:\: ctrlaltdel/' d /etc/inittab# new user password lifetime echo pass_max_days 90 >> /etc/login.defs #新建用户口令更改最小间隔天数echo pass_min_days 5 >> /etc/login.defs# password before expiration warning days echo pass _warn_age 7 >> /etc/login.defs #口令最小长度 echo PASS_MIN_LEN 8 >> /etc/login.defs# automatically exits after 300 seconds without operation echo tmout=300 >> /etc/profile #保留最新执行的5条命令echo HISTFILESIZE=5 >> /etc/profile echo HISTSIZE=5 > > /etc/profile# new file and folder default permissions #echo umask 027 >> /etc/profile #echo alias rm= ' rm -i ' > > /etc/profile#echo alias ls= ' Ls -aol ' >> /etc/profile# password complexity requirements echo password required pam_cracklib.so use_authtok minlen=8 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 >> /etc/pam.d/common-password# set to password continuous error 5 times lock, Lockout Time 300 sec echo auth required pam_tally2.so deny=5 onerr=fail no_magic_root unlock_time=300 >> /etc/pam.d/common-password #口令历史策略echo password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok remember=5 >> /etc/pam.d/common-password #禁止pingecho 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all #禁止IP伪装echo nospoof on >> / etc/host.conf #创建新的用户useradd osadminecho password | passwd --stdin osadmin >> / dev/null# configuring SSH to use Protocol 2 version echo protocol 2 >> /etc/ssh/sshd_config# disable root using SSH remote login echo permitrootlogin no >> /etc/ssh/sshd_config
This article is from the "BOM water Year _" blog, please be sure to keep this source http://timefiles.blog.51cto.com/8475652/1884132
Linux system Security Hardening script