安装CenTos系统后,给服务器进行基础优化:
关闭SElinux
SElinux是美国国家安全局NSA对于强制访问控制的实现
[root@192 ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@192 ~]# sed -i 's#STLINUX=.*#SELINUX=disabled#g' /etc/selinux/config
[root@192 ~]# setenforce 0
[root@192 ~]#
精简开机系统启动
linux服务器在运行过程中,会有很多默认的服务在运行,而且这些服务通常是没用,这些服务占用了系统资源,存在安全隐患,关闭这些没用的服务
重要的服务,需要开启:
1) sshd
远程连接服务,需要开启,要不然无法连接linux。
2) rsyslog
是操作系统中提供的一种机制,系统的守护程序通常会使用rsyslog 将各种信息写到系统日志文件中,
3) . network
系统启动时,若想关闭或者激活各个网络接口,就必须启动该服务
4) cron
一次性计划任务: at
周期计划任务: crontab
5) sysstat
该服务包括监控系统性能及效率的一组工具。这些工具对于收集系统的性能数据很有帮助:核心工具包:
iostat : cpu使用率及硬盘吞吐效率工具
mpstat:提供单个或者多个处理器的数据
sar 负责收集,报告并存储系统活跃的信息
关闭防火墙
[root@192 ~]# iptables -F
[root@192 ~]# /etc/init.d/iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
[root@192 ~]# chkconfig iptables off
[root@192 ~]# service iptables stop
[root@192 ~]#
最小化原则安装
1 )linux系统最小化安装,最选包最小化,yum安装软件包也要最小化,没用的包不安装。
2) 操作系统命令最小化
登录linux用户量最小化,不要使用root,使用普通用户即可
4) 普通授权最小化,即只给必须的管理系统的命令
5)linux系统文件及目录权限设置最小化,禁止随便修改,更改,删除。
更改ssh服务端远程登录的配置
1) 端口不要使用22
2) UseDNS no 是否使用DNS,设置为no之后登录速度会快
3)#PermitRootLogin no 设置不允许root登录
4)GSSAPIAuthentication no 解决ssh链接慢的问题
5) PasswordAuthentication yes 密码验证是必须的,默认yes
PermitEmptyPasswords no 空密码是否允许登录
7)#LoginGraceTime 2m 当使用者连接上ssh server的时候,会出现输入密码的画面,在这个画面中,多久没有成功连接上就强迫断线
[root@192 ~]# service sshd restart
停止 sshd: [确定]
正在启动 sshd: [确定]
[root@192 ~]# ssh 192.168.148.156 root@192.168.148.156 password:123456
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
root@192.168.148.156's password:
bash: root@192.168.148.156: command not found
[root@192 ~]#
8) #PrintMotd yes //登入后是否显示一些信息,比如上次登录时间,地点。
[root@192 ~]# ssh 192.168.148.156
The authenticity of host '192.168.148.156 (192.168.148.156)' can't be established.
RSA key fingerprint is f0:2c:f5:f3:70:a4:45:b0:e9:bb:9f:ea:fc:76:02:d7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.148.156' (RSA) to the list of known hosts.
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
root@192.168.148.156's password:
Last login: Fri Mar 13 11:00:47 2020 from 192.168.148.1
[root@192 ~]#
sudo控制用户对系统命令的最小化
设置Linux服务器的时间同步
[root@192 ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@192 ~]#
关于ntp服务
加大服务器文件描述符
[root@192 ~]# vim /etc/security/limits.conf
[root@192 ~]# ulimit -n
1024
[root@192 ~]#
禁止 ping
[root@192 ~]# echo 'net.ipv4.icmp_echo_ignore_all = 1' >>/etc/sysctl.conf
[root@192 ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.icmp_echo_ignore_all = 1
[root@192 ~]#
等等…
https://blog.youkuaiyun.com/xinshuzhan/article/details/104694546
https://blog.youkuaiyun.com/fanren224/article/details/79971359