失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > centos7 系统安全加固方案

centos7 系统安全加固方案

时间:2020-06-28 15:11:10

相关推荐

centos7 系统安全加固方案

****centos7 系统安全加固方案****

一.密码长度与有效期

1、用户的默认设置文件:/etc/login.defs

2、/etc/login.defs文件说明

3、查看默认配置

cat /etc/login.defs |grep PASS_ |grep -v ‘#’

PASS_MAX_DAYS 99999

PASS_MIN_DAYS 0

PASS_MIN_LEN 5

PASS_WARN_AGE 7

4、加固方案

5、

(1)备份配置文件:

cp -a /etc/login.defs /etc/login.defs.default

(2)编辑配置文件并将相关参数改成如下

# vi /etc/login.defs

PASS_MAX_DAYS 90

PASS_MIN_DAYS 6

PASS_MIN_LEN 8

PASS_WARN_AGE 30

二、密码复杂度

1、查看默认配置

# cat /etc/pam.d/system-auth | grep “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 authtok_type=

2、相关字段说明

*try_first_pass*而当pam_unix验证模块与password验证类型一起使用时,该选项主要用来防止用户新设定的密码与以前的旧密码相同。

*minlen=8*最小长度8位

*difok=5*新、旧密码最少5个字符不同

*dcredit=-1*最少1个数字

*lcredit=-1*最少1个小写字符,(ucredit=-1:最少1个大写字符)

*ocredit=-1*最少1个特殊字符

*retry=1*1次错误后返回错误信息

*type=xxx*此选项用来修改缺省的密码提示文本

3、/etc/login.defs文件的pass_min_len 参数并不具备强制性,测试仍然可以设置7位密码。最终需要cracklib来实现。

3、加固方案

(1)备份配置文件:

# cp -a /etc/pam.d/system-auth /etc/pam.d/system-auth.default

(2)编辑配置文件

# vi /etc/pam.d/system-auth

注释:password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=

在其下面新增1行:password requisite pam_cracklib.so try_first_pass minlen=8 difok=5 dcredit=-1 lcredit=-1 ocredit=-1 retry=1 type=

(3)保存配置文件

三.新口令不能与4个最近使用的相同

*1、查看默认配置*

# cat /etc/pam.d/system-auth |grep use_authtok

password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok

2、*加固方案*

(1)备份配置文件

(2)编辑配置文件:# vi /etc/pam.d/system-auth

在password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok 行的后面添加remember=5

(4)保存配置文件

四.设置会话超时(5分钟

*1、********默认配置:无*

*2、********加固方案:*

(1)备份配置文件:

# cp -a /etc/profile /etc/profile.default

(2)编辑配置文件:

vi /etc/profile

在文件的末尾添加参数

export TMOUT=300

(3)保存配置文件

五.设置history命令时间戳

*1、********默认配置: 无*

*2、********加固方案:*

(1)备份配置文件:

(2)编辑配置文件:

vi /etc/profile

在文件的末尾添加参数

export HISTTIMEFORMAT="%F %Twhoami"

(4)保存配置文件

六.设置登陆失败锁定(终端登录)

通过终端登录,5次登录失败后锁定账号30分钟,锁定期间此账号无法再次登录。

*1、********默认配置:无*

*2、********加固方案:*

1.备份配置文件

2.编辑配置文件:

# vi /etc/pam.d/system-auth

在# User changes will be destroyed the next time authconfig is run.行的下面,添加

auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root root_unlock_time=1800

3.保存配置文件

七.禁止root通过ssh远程登录

1、*默认配置:*

# cat /etc/ssh/sshd_config |grep PermitRootLogin

#PermitRootLogin yes

2、*加固方案:*

(1)备份配置文件

# cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.default

(2)编辑配置文件

vi /etc/ssh/sshd_config

将配置参数#PermitRootLogin yes改成PermitRootLogin no

(3)保存配置文件

(4)重启ssh服务

# /etc/init.d/sshd restart

八.SSH 配置参数增强

*1.备份配置文件*

*2.编辑配置文件*

#vi /etc/ssh/sshd_config

1.备份配置文件2.编辑配置文件

#vi /etc/ssh/sshd_config

(1)禁止空密码登录

将#PermitEmptyPasswords no参数的注释符号去掉,改成

PermitEmptyPasswords no

(2)关闭ssh的tcp转发

将#AllowTcpForwarding yes参数改成

AllowTcpForwarding no

(3)关闭S/KEY(质疑-应答)认证方式

将#ChallengeResponseAuthentication yes参数,改成

ChallengeResponseAuthentication no

(4)关闭基于GSSAPI 的用户认证

将GSSAPIAuthentication yes参数,改成

GSSAPIAuthentication no

*3.********保存配置文件*

*4.重启ssh服务*

九.设置SSH登录警告语

*1.********默认配置:无*

*2.********加固方案:*

(1)备份配置文件

(2)编辑配置文件

#vim /etc/ssh/sshd_config

找到#Banner none参数,在其下一行,增加

Banner /etc/ssh/alert

(3)保存配置文件

(4)新增告警信息文件.

#vim /etc/ssh/alert

文件内容,设置成

这里的内容自己定义,可以提示一下登录的用户引起运维人员重视

Warning!!!Any Access Without Permission Is Forbidden!!!

(5)保存后重启ssh服务

十设置umask值

*1、********默认配置:*

# umask

0022

3、*加固方案:*

将umask值设置成0027,用于拿掉新增目录与文件的非所有者和所有者所属组的访问权限。

默认情况下:

新增目录权限755,即rxwr-xr-x

新增文件权限644,即rw-r–r—

加固后:

新增目录权限750,即rxwr-x—

新增文件权限640,即rw-r-----

(1)备份配置文件

# cp -a /etc/bashrc /etc/bashrc.default

(2)编辑配置文件

# vi /etc/bashrc

在文件末尾增加参数

umask 027

(3)保存配置文件

(4)备份配置文件

# cp -a /etc/profile /etc/pr ofile.default

(5)编辑配置文件

# vi /etc/profile

在文件末尾增加参数

umask 027

(6)保存配置文件

十一.Control-Alt-Delete 键盘重启系统命令

*1.********默认配置:*

ls /usr/lib/systemd/system/ctrl-alt-del.target

*2.********加固方案:*

(1)备份配置文件

cp -a /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.default

(2)移除该原源文件

rm -rf /usr/lib/systemd/system/ctrl-alt-del.target

十二. 隐藏系统版本信息:登录界面显示系统版本信息

加固方案:

#mv /etc/issue /etc/issue.bak

#mv /etc/ /etc/.bak

13.最大文件打开数(文件句柄数):修改所有用户的最大文件打开数为65535

*1、********默认配置:*

[root@i-1y3we23j ~]# ulimit -n1024

*2、********加固方案:*

(1)备份配置文件

cp -a /etc/security/limits.conf /etc/security/limits.conf.default

(2)添加以下两行配置到该文件最后

* soft nofile 65535

* hard nofile 65535

十四.用户最大进程数:修改所有用户的最大进程数为65535

*1、********默认配置:*

[root@i-1y3we23j ~]# cat /etc/security/limits.d/20-nproc.conf

# Default limit for number of user’s processes to prevent# accidental fork bombs.

# See rhbz #432903 for reasoning.

* soft nproc 4096

root soft nproc unlimited

*2、加固方案:*

(1)备份配置文件

cp -a /etc/security/limits.d/20-nproc.conf /etc/security/limits.d/20-nproc.conf.default

(2)修改配置文件vim /etc/security/limits.d/20-nproc.conf

* soft nproc 65535

* hard nproc 65535

十五、系统参数调优

*1、********默认配置:无*

*2、********加固方案:*

(1)备份配置文件

cp -a /etc/sysctl.conf /etc/sysctl.conf.default

(2)添加以下调优参数到该文件中

net.ipv4.ip_forward = 1

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.route.gc_timeout = 20

net.ipv4.tcp_retries2 = 5

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_wmem = 8192 131072 16777216

net.ipv4.tcp_rmem = 32768 131072 16777216

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.core.somaxconn = 262144

dev_max_backlog = 262144

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.route.gc_timeout = 20

net.ipv4.ip_local_port_range = 10024 65535

net.ipv4.tcp_retries2 = 5

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_keepalive_time = 1800

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.tcp_keepalive_intvl = 30

net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_wmem = 8192 131072 16777216

net.ipv4.tcp_rmem = 32768 131072 16777216

net.ipv4.tcp_mem = 94500000 915000000 927000000

fs.file-max = 65535

kernel.pid_max = 65536

net.ipv4.tcp_wmem = 4096 87380 8388608

net.core.wmem_max = 8388608

dev_max_backlog = 5000

net.ipv4.tcp_window_scaling = 1

net.ipv4.tcp_max_syn_backlog = 10240

dev_max_backlog = 262144

net.core.somaxconn = 262144

net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 10000 65000

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_max_tw_buckets = 36000

如果觉得《centos7 系统安全加固方案》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。