1、linux系统安全加固方案1概述1.1适用围本方案适用于银视通信息科技XXlinux主机平安加固,供运维人员参考对linux主机进展平安加固。2用户账户平安加固2.1修改用户密码策略1修改前备份配置文件:/etc/login.defscp /etc/login.defs /etc/login.defs.bak2修改编辑配置文件:vi /etc/login.defs,修改如下配置:PASS_MAX_DAYS 90 用户的密码不过期最多的天数PASS_MIN_DAYS 0 密码修改之间最小的天数PASS_MIN_LEN 8 密码最小长度PASS_WARN_AGE 7 (口令失效前多少天开场通知用户
2、更改密码)3回退操作* cp /etc/login.defs.bak /etc/login.defs2.2锁定或删除系统中与效劳运行,运维无关的的用户1查看系统中的用户并确定无用的用户* more /etc/passwd2锁定不使用的账户锁定或删除用户根据自己的需求操作一项即可锁定不使用的账户:* usermod -L username 或删除不使用的账户:* userdel -f username3回退操作用户锁定后当使用时可解除锁定,解除锁定命令为:* usermod -U username2.3锁定或删除系统中不使用的组1操作前备份组配置文件/etc/group* cp /etc/gro
3、up /etc/group.bak2查看系统中的组并确定不使用的组* cat /etc/group(3)删除或锁定不使用的组锁定不使用的组:修改组配置文件/etc/group,在不使用的组前加“*注释掉该组即可删除不使用的组:* groupdel groupname4回退操作* cp /etc/group.bak /etc/group2.4限制密码的最小长度(1)操作前备份组配置文件/etc/pam.d/system-auth* cp /etc/pam.d /etc/pam.d.bak(2)设置密码的最小长度为8修改配置文件/etc/pam.d,在行password requisite pam
4、_pwquality.so try_first_pass local_users_only retry=3 authtok_type=中添加“minlen=8,或使用sed修改:* sed -i s*password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=*password requisite pam_pwquality.so try_first_pass local_users_only retry=3 minlen=8 authtok_type=*g /etc/pam.
5、d/system-auth(3)回退操作* cp /etc/pam.d.bak /etc/pam.d3用户登录平安设置3.1制止root用户远程登录1修改前备份ssh配置文件/etc/ssh/sshd_conf* cp /etc/ssh/sshd_conf /etc/ssh/sshd_conf.bak2修改ssh效劳配置文件不允许root用户远程登录编辑/etc/ssh/sshd_config找到“*PermitRootLogin yes去掉注释并修改为“PermitRootLogin no或者使用sed修改,修改命令为:* sed -i s*PermitRootLogin yesPermit
6、RootLogin nog /etc/ssh/sshd_config3修改完成后重启ssh效劳Centos6.x为:* service sshd restartCentos7.x为:* systemctl restart sshd.service4回退操作* cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config3.2设置远程ssh登录超时时间1修改前备份ssh效劳配置文件/etc/ssh/sshd_config* cp /etc/ssh/sshd_conf /etc/ssh/sshd_conf.bak2设置远程ssh登录长时间不操作退出登录编辑/et
7、c/ssh/sshd_conf将*ClientAliveInterval 0修改为ClientAliveInterval ,将*ClientAliveCountMax 3去掉注释,或执行如下命令:* sed -i s*ClientAliveInterval 0ClientAliveInterval g /etc/ssh/sshd_config* sed -i s*ClientAliveCountMax 3ClientAliveCountMax 3g /etc/ssh/sshd_config 3配置完成后保存并重启ssh效劳Centos6.x为:* service sshd restartCen
8、tos7.x为:* systemctl restart sshd.service4回退操作* cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config3.3设置当用户连续登录失败三次,锁定用户30分钟1配置前备份配置文件/etc/pam.d/sshd* cp /etc/pam.d/sshd /etc/pam.d/sshd.bak2设置当用户连续输入密码三次时,锁定该用户30分钟修改配置文件/etc/pam.d/sshd,在配置文件的第二行添加容:auth required pam_tally2.so deny=3 unlock_time=3003假设修改
9、配置文件出现错误,回退即可,回退操作:* cp /etc/pam.d/sshd.bak /etc/pam.d/sshd3.4设置用户不能使用最近五次使用过的密码1配置前备份配置文件/etc/pam.d/sshd* cp /etc/pam.d/system-auth /etc/pam.d/system-auth.bak2配置用户不能使用最近五次使用的密码修改配置文件/etc/pam.d/sshd,找到行password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok,在最后参加remember=10,或
10、使用sed修改* sed -i s*password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtokpassword sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=10g /etc/ssh/sshd_config 3回退操作* cp /etc/pam.d/sshd.bak /etc/pam.d/sshd3.5设置登陆系统账户超时自动退出登陆1设置登录系统的账号长时间不操作时自动登出修改系统
11、环境变量配置文件/etc/profile,在文件的末尾参加TMOUT=,使登录系统的用户三分钟不操作系统时自动退出登录。 * echo TMOUT= /etc/profile2使配置生效执行命令: * . /etc/profile *或 source /etc/profile3回退操作删除在配置文件/etc/profile中添加的TMOUT=,执行命令. /etc/profile使配置生效。4系统平安加固4.1关闭系统中与系统正常运行、业务无关的效劳1查看系统中的所有效劳及运行级别,并确定哪些效劳是与系统的正常运行及业务无关的效劳。* chkconfig -list 2关闭系统中不用的效劳*
12、chkconfig servername off3回退操作,如果意外关闭了与系统业务运行相关的效劳,可将该效劳开启* chkconfig servername on4.2禁用“CTRL+ALT+DEL重启系统1rhel6.x中禁用“ctrl+alt+del键重启系统修改配置文件“/etc/init/control-alt-delete.conf,注释掉行“start on control-alt-delete。或用sed命令修改:* sed -i sstart on control-alt-delete*start on control-alt-deleteg /etc/init/contro
13、l-alt-delete.conf 2rhel7.x中禁用“ctrl+alt+del键重启系统修改配置文件“/usr/lib/systemd/system/ctrl-alt-del.target,注释掉所有容。3使修改的配置生效* init q4.3加密grub菜单1、加密Redhat6.x grub菜单(1)备份配置文件/boot/grub/grub.conf* cp /boot/grub/grub.conf /boot/grub/grub.conf.bak(2)将密码生成秘钥* grub-md5-crypt Password: Retype password: $1$nCPeR/$mUKE
14、eqnBp8G.P.Hrrreus.(3)为grub加密修改配置文件/boot/grub/grub.conf,在timeout=5行下参加password -md5 $1$CgxdR/$9ipaqi8aVriEpF0nvfd8x.,$1$CgxdR/$9ipaqi8aVriEpF0nvfd8x.为加密后的密码。(4)回退* cp /boot/grub/grub.conf /boot/grub/grub.conf.bak或者删除参加行password -md5 $1$CgxdR/$9ipaqi8aVriEpF0nvfd8x.2、加密redhat7.xgrub菜单1在/etc/grub.d/00_header文件末尾,添加以下容cat EOFset superusers=adminpassword admin qwe123E0F2重新编译生成grub.cfg文件* grub2-mkconfig -o /boot/grub2/grub.cfg(3)回退操作删除/etc/grub.d/00_header中添加的容,并重新编译生成grub.cfg文件