当前位置:网站首页>centos7 server security policy
centos7 server security policy
2022-07-29 19:01:00 【q908544703】
目录
一、基于centos7设置密码策略
CentOS7/RHEL7 开始使用pam_pwquality模块进行密码复杂度策略的控制管理.pam_pwquality替换了原来Centos6/RHEL6中的pam_cracklib模块,并向后兼容.
- (1)编辑system-auth
vim /etc/pam.d/system-auth
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= minlen=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1 difok=5 enforce_for_root

minlen = 8,密码长度至少8位;
lcredit=-1,至少包含一个小写字母;
ucredit=-1,至少包含一个大写字母;
dcredit=-1,At least contain the number to be given;
ocredit=-1,至少包含一个特殊字符;
difok=5,The new password is at most a duplicate of the old password5个字符;
enforce_for_root,对rootEnforce password complexity policies.
(2)参数说明
**负数:represents the minimum number of occurrences,正数:Represents the maximum number of occurrences**
- minlen:表示密码长度
- lcredit=N 当N>0时表示新密码中小写字母出现的最多次数;当N<0时表示新密码中小写字母出现最少次数
- ucredit=N 当N>0时表示新密码中大写字母出现的最多次数;当N<0时表示新密码中大写字母出现最少次数
- dcredit=N: N >= 0:密码中最多有多少个数字;N < 0密码中最少有多少个数字. dcredit=-1
密码中最少有1个数字 - ocredit=N:N >= 0:The maximum number of special letters in the password;N < 0The minimum number of special letters in the password.ocredit=-1
密码中至少有1个特殊字符 - difok=5,The new password is at most a duplicate of the old password5个字符;
- enforce_for_root,对rootEnforce password complexity policies.
- (3)验证密码策略

二、基于centos7Set the authentication policy
User login failure handling function should be set,可采取结束会话、限制非法登录次数和自动退出等措施.
1).策略配置
vim /etc/pam.d/sshd
auth required pam_tally2.so onerr=fail deny=2 unlock_time=120 root_unlock_time=120

2).参数说明
auth required pam_tally2.so onerr=fail deny=5 unlock_time=1800 root_unlock_time=1800
onerr=fail 表⽰Defines the default return value when an error occurs;
even_deny_root 表⽰也限制root⽤户;
deny 表⽰设置普通⽤户和root⽤The highest number of consecutive wrong logins by users⼤次数,more than the most⼤次数,lock it⽤户;
unlock_time 表⽰Set to normal⽤after the user is locked,多少时间后解锁,单位是秒;
root_unlock_time 表⽰设定root⽤after the user is locked,多少时间后解锁,单位是秒
3).查看用户登录失败的次数
pam_tally2 --user 用户名

4).解锁指定用户
pam_tally2 -r -u 用户名

三、Set the login session timeout
The session timeout feature for the login terminal should be set.
vim /etc/profile
TMOUT=600 #600秒超时
source /etc/profile
执行vi /etc/profile命令打开配置文件
在vimquery in the editorTMOUT(可以通过/TMOUT方式查询)
将TMOUTThe value of is changed to the duration that needs to be set(单位秒,0为不限制)
:wq保存退出
执行source /etc/profile保存即可
Add the following two codes:
TMOUT=300
export TMOUT

四、设置密码有效期
vim /etc/login.defs
1).配置策略
#密码的最大有效期
PASS_MAX_DAYS 180
#登录密码最短修改时间,增加可以防止非法用户短期更改多次
PASS_MIN_DAYS 1
#密码最小长度,pam_pwquality设置优先
PASS_MIN_LEN 8
#密码失效前多少天在用户登录时通知用户修改密码
PASS_WARN_AGE 7

#The above settings only take effect for new users,The original user does not take effect.
Existing users set the password validity period,可以使用命令:
chage -M 180 用户
chage:密码失效是通过此命令来管理的.
参数意思:
-m 密码可更改的最小天数.为零时代表任何时候都可以更改密码.
-M 密码保持有效的最大天数.
-W 用户密码到期前,提前收到警告信息的天数.
-E 帐号到期的日期.过了这天,此帐号将不可用.
-d 上一次更改的日期
-I 停滞时期.如果一个密码已过期这些天,那么此帐号将不可用.
-l 例出当前的设置.由非特权用户来确定他们的密码或帐号何时过期.

2).View the password expiration policy
[[email protected] ~]# chage -M 90 test #密码有效期90天
[[email protected] ~]# chage -d 0 test #强制用户登陆时修改口令
[[email protected] ~]# chage -d 0 -m 0 -M 90 -W 15 test #强制用户下次登陆时修改密码,并且设置密码最低有效期0和最高有限期90,提前15天发警报提示
[[email protected] ~]# chage -E '2014-09-30' test # test这个账号的有效期是2014-09-30
五、禁止root 远程登录
使用命令 vim /etc/ssh/sshd_config 编辑该文件
找到 PermitRootLogin yes 改为 找到 PermitRootLogin no
然后重启 service sshd restart

六、Limit remote login addresses
对于通过IPProtocol for remote maintenance of equipment,The device should support the ability to log in to the deviceIPSet the address range.
1、/etc/hosts.allowis set to allow accessIP地址范围.
2、/etc/hosts.denyDeny all remote access is set in .sshd:ALL
Both are compliant,否则不合规.
vim /etc/hosts.allow
格式案例:
sshd:192.168.212.*:allow
sshd:192.168.148.*:allow
sshd:192.168.8.*:allow
sshd:92.168.145.*:allow
sshd:192.168.209.*:allow
sshd:192.168.215.*:allow
sshd:192.168.141.*:allow
sshd:192.168.1.*:allow
sshd:192.168.3.*:allow
sshd:192.168.8.*:allow
sshd:192.168.146.*:allow
sshd:192.168.*:allow
sshd:192.168.*:allow
vim /etc/hosts.deny
sshd:ALL
验证方法:
cat /etc/hosts.allow|grep -v "^*\|^#\|^$"
cat /etc/hosts.deny|grep -v "^*\|^#\|^$"
七、Install anti-malware software on the server
LinuxAntivirus softwareClamav的安装
1).安装
yum install clamav clamav-server clamav-data clamav-update \
clamav-filesystem clamav-scanner-systemd \
clamav-devel clamav-lib clamav-server-systemd \
pcre* gcc zlib zlib-devel libssl-devel libssl openssl
2).更新病毒库
#先停止freshclam服务
systemctl stop clamav-freshclam.service
#自动更新
freshclam
#重启freshclam服务
systemctl start clamav-freshclam.service
3).常用命令
#重启freshclam服务
systemctl start clamav-freshclam.service
#查看服务状态
systemctl status clamav-freshclam.service
#开机启动程序
systemctl enable clamav-freshclam.service
#停止freshclam服务
systemctl stop clamav-freshclam.service
4).杀毒
扫描指令:clamscan
通用,不依赖服务,命令参数较多,执行速度稍慢
用clamscan扫描,It can be used without starting the service
-r 递归扫描子目录
-i 只显示发现的病毒文件
--no-summary 不显示统计信息
扫描参数:
-r/--recursive[=yes/no] 所有文件
--log=FILE/-l FILE 增加扫描报告
--copy[路径] Copy infected files to [路径]
--move [路径] Move infected files to [路径]
--remove [路径] Delete infected files
--quiet 只输出错误消息
--infected/-i 只输出感染文件
--suppress-ok-results/-o 跳过扫描OK的文件
--bell 扫描到病毒文件发出警报声音
--unzip(unrar) 解压压缩文件扫描
#扫描所有文件并且显示有问题的文件的扫描结果
clamscan -r --bell -i /
#Only virus information found is displayed
clamscan --no-summary -ri /app
#扫描app
clamscan --infected --remove --recursive /app
5).定时杀毒
定时杀毒
#让服务器每天晚上定时更新和杀毒,保存杀毒日志,crontab文件如下:
2 3 * * * /usr/local/clamav/bin/freshclam --quiet
23 3 * * * /usr/local/clamav/bin/clamscan -r /app --remove -l /var/log/clamscan.log
边栏推荐
- 本周投融报:CeFi积聚风投吸引力
- The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"
- 请问一下,我这个调度任务显示执行成功,但是并没有成功,我这个任务是odps sql ins
- 银行有没有必要建立数据中台?看完你就明白了
- 【深度学习】使用yolov5对数据进行预标注
- crontab执行定时任务报错的问题
- 分批数据遍历的优化
- 解决报错Unsupported field: HourOfDay
- 数据监控体系是什么?该怎么搭建?
- 字节跳动使用 Flink State 的经验分享
猜你喜欢

The service failure agent how to get things

Pagination with LIMIT

EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?

11.99万起,东风风行游艇上市,产品力越级诚意满满

KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!

Mathematical Analysis_Proof_Two Important Limits (Tongji Version)

431页14万字政府信息化管理平台解决方案

字节跳动使用 Flink State 的经验分享

In the Chinese ToB market, it is too difficult to choose the right supplier
![[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server](/img/4a/7156470e8d96c7709001bac88e872c.png)
[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server
随机推荐
[Operation and maintenance] ssh tunneling relies on the 22 port of ssh to realize the interface service of accessing the remote server
500强企业研发效能提升课,今晚开课啦!
AMD收购赛灵思已获两家公司股东同意
招聘|字节跳动云原生计算,期待你的加入
【码蹄集新手村600题】给定一个整数n,求floor(n/x)=y 中 x,y 的所有值
The service failure agent how to get things
【英语考研词汇训练营】Day 17 —— espresso,ultimate,gradually,detect,dimension
MySQL数据库的七种约束语法格式和使用详解&约束的总结
【MySQL】如何向mysql数据库插入当前时间
字节跳动使用 Flink State 的经验分享
[Deep Learning] Use yolov5 to pre-label data
不同的 DAO 对世界带来的改变
【深度学习】使用yolov5对数据进行预标注
【QT】Qt获取前几天/后几天的时间
MySql解决GROUP BY出现的问题
解决 @RefreshScope 导致定时任务注解 @Scheduled 失效
今年一季度全球PC出货量同比增长32%,创21年来最快增速
实时数仓:咸鱼的实时数仓经验分享
字节跳动 Flink 单点恢复功能及 Regional CheckPoint 优化实践
为什么你的分布式数据中心需要一个全栈智能运维平台?