当前位置:网站首页>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
边栏推荐
- 最近很郁闷
- 不惧AMD及Arm挑战,英特尔称霸服务器市场的秘诀是什么?
- 北汇信息继续扩大V2X测试服务,扎根重庆,服务全国
- 三轮电摩专用之48V动力锂电池组-产品规格书
- SK海力士工厂发生氢氟酸泄漏,3名工人受伤!官方称不会影响生产
- 多线程并发Callable
- redis学习三redis里的list、set、hash、sorted_set、skiplist
- 【英语考研词汇训练营】Day 17 —— espresso,ultimate,gradually,detect,dimension
- HCIP笔记第十四天
- [Code Hoof Set Novice Village 600 Questions] Find the distance between two points in the space rectangular coordinate system
猜你喜欢
随机推荐
QMI8658 - 6轴传感器学习笔记
P4775 [NOI2018] 情报中心(线段树合并)
【考研英语词汇训练营】Day 16 —— bankrupt,remain,regulate,construct,reflect
P4769 [NOI2018] 冒泡排序(组合数学)
宏定义小方法
解决报错Unsupported field: HourOfDay
【运维】ssh tunneling 依靠ssh的22端口实现访问远程服务器的接口服务
[STM32CubeMX] STM32H743 configuration IAP upgrade
U盘拔出时总是提示有程序正在使用?
商业智能BI为什么能在数字化时代成为企业的基础建设
亿级用户背后的字节跳动云原生计算最佳实践
在 Web3中网络效应
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
Xatlas source code parsing (7)
UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
【STM32CubeMX】STM32H743配置IAP升级
EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
开放原子开源基金会为白金、黄金、白银捐赠人授牌,CSDN荣获黄金捐赠人
Google Cloud X Kyligence|如何从业务视角管理数据湖?
不惧AMD及Arm挑战,英特尔称霸服务器市场的秘诀是什么?