一、 操作系统
1 密码长度与有效期
[root@i-1y3we23j ~]# cat /etc/login.defs |grep PASS_ |grep -v '#'
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
2 密码复杂度
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.保存配置文件
3 设置会话超时(5分钟)
1.备份配置文件:
# cp -a /etc/profile /etc/profile.default
2.编辑配置文件:
vi /etc/profile
在文件的末尾添加参数
export TMOUT=300
4 设置history命令时间戳
1.备份配置文件:
2.编辑配置文件:
vi /etc/profile
在文件的末尾添加参数
export HISTTIMEFORMAT="%F %T `whoami` "
5 设置登陆失败锁定(终端登录)
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
6 禁止root通过ssh远程登录
1.备份配置文件
# cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.default
2.编辑配置文件
vi /etc/ssh/sshd_config
将配置参数#PermitRootLogin yes改成PermitRootLogin no
3.创建普通用户
useradd admin
passwd admin
4.重启sshd服务
systemctl restart sshd.service
7 SSH 配置参数增强
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服务
8 设置SSH登录警告语
1.备份配置文件
# 略
2.编辑配置文件
#vi /etc/ssh/sshd_config
找到#Banner none参数,在其下一行,增加
Banner /etc/ssh/alert
3.保存配置文件
4新增告警信息文件.
#vi /etc/ssh/alert
文件内容,设置成
*******************************************************
这里的内容自己定义,可以提示一下登录的用户引起运维人员重视
Warning!!!Any Access Without Permission Is Forbidden!!!
*******************************************************
5.保存后重启ssh服
9 设置umask值
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.保存配置文件
10 禁止Control-Alt-Delete 键盘重启系统命令
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
11 隐藏系统版本信息
执行以下命令:
#mv /etc/issue /etc/issue.bak
#mv /etc/issue.net /etc/issue.net.bak
12 最大文件打开数(文件句柄数)
1.备份配置文件
cp -a /etc/security/limits.conf /etc/security/limits.conf.default
2.添加以下两行配置到该文件最后
* soft nofile 65535
* hard nofile 65535
13 用户最大进程数
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
14 系统参数调优
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
net.core.netdev_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
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_max_syn_backlog = 10240
net.core.netdev_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
15 关闭不必要的服务
使用 systemctl list-unit-files 可以查看启动项
systemctl list-unit-files | grep enable
abrt-ccpp.service enabled
abrt为auto bug report的缩写 用于bug报告 关闭
abrt-oops.service enabled ----------------------
abrt-vmcore.service enabled ----------------------
abrt-xorg.service enabled ----------------------
abrtd.service enabled ----------------------
auditd.service enabled 安全审计 保留
autovt@.service enabled 登陆相关 保留
crond.service enabled 定时任务 保留
dbus-org.freedesktop.NetworkManager.service enabled 桌面网卡管理 关闭
dbus-org.freedesktop.nm-dispatcher.service enabled -----------------
getty@.service enabled tty控制台相关 保留
irqbalance.service enabled 优化系统中断分配 保留
kdump.service enabled 内核崩溃信息捕获 自定
microcode.service enabled 处理器稳定性增强 保留
NetworkManager-dispatcher.service enabled 网卡守护进程 关闭
NetworkManager.service enabled ----------------------
postfix.service enabled 邮件服务 关闭
rsyslog.service enabled 日志服务 保留
snmpd.service enabled snmp监控 数据抓取 保留
sshd.service enabled ssh登陆 保留
systemd-readahead-collect.service enabled 内核调用--预读取 保留
systemd-readahead-drop.service enabled ----------------------
systemd-readahead-replay.service enabled ----------------------
tuned.service enabled
default.target enabled 默认启动项 multi-user.target的软连接 保留
multi-user.target enabled 启动用户命令环境 保留
remote-fs.target enabled 集合远程文件挂载点 自定
runlevel2.target enabled 运行级别 用于兼容6的SysV 保留
runlevel3.target enabled ----------------------
runlevel4.target enabled ----------------------
安装必要的补丁
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc
开启防火墙
systemctl enable firewalld.service