centos7安全相关设置

centos7安全相关设置

初始化及软件安装


## 固定IP地址

## 关闭SELINUX
[root@c72 ~]# vim /etc/selinux/config 
SELINUX=disabled

## 更改主机名,让hosts文件与当前主机名保持对应关系
echo bre_sch > /etc/hostname
[root@c72 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 bre_sch
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 bre_sch

# 关闭firewalld,后面的防火墙设置使用iptables
systemctl stop firewalld
systemctl disable firewalld

## 软件安装
cd /etc/yum.repos.d/
rm -rf ./*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce wget curl vim lrzsz nmap cifs-utils samba-client nfs-utils samba openssh iptables-services 
yum install -y wget yum-utils device-mapper-persistent-data lvm2 net-tools
systemctl start docker
systemctl enable docker

user&密码

## 创建单独的登录用户,并设置满足复杂性要求
useradd bresee ; echo 123456 | passwd --stdin bresee

ssh安全设置

## ssh连接加速,不允许反向解析
UseDNS no

## 不允许root直接登录 ,仅允许普通用户登录
PermitRootlogin no

## 更改端口为7777
Port 7777

## SSH登录连续输错五次密码,账号锁定30秒
vi /etc/pam.d/sshd
	auth       required     pam_tally2.so deny=5 unlock_time=30
systemctl restart sshd

防火墙设置

仅开放了ssh、http和https三种服务

# 清空规划
iptables -F
# 开启80
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -j ACCEPT
# 开启443
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --sport 443 -j ACCEPT
## 开启ssh侦听的7777
iptables -A INPUT -p tcp --dport 7777 -j ACCEPT
iptables -A INPUT -p tcp --sport 7777 -j ACCEPT
## 开启ICMP
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 0 -j ACCEPT
## 开启DNS
iptables -A INPUT -p udp --dport 53 -j ACCEPT 
iptables -A INPUT -p udp --sport 53 -j ACCEPT
# 默认拒绝所有
iptables -P INPUT DROP
# 保存
service iptables save

# 开机启动
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service

系统安全设置

----------------------------------------------# 设置grub密码
## 生成密码*Ab123456
grub2-mkpasswd-pbkdf2  
## 在/etc/grub.d/00_header引用密码
vim /etc/grub.d/00_header
	cat <<EOF
	set superusers='root'
	password_pbkdf2 root grub.p54CBD4341FC4A71B90E543581646B4E7EAE920C54A
	E0F
## 重新生成
grub2-mkconfig  -o  /boot/grub2/grub.cfg
-------------------------------------禁止control+alt+delete键盘重启系统
mv /usr/lib/systemd/system/ctrl-alt-del.target /tmp

-------------------------------------history带时间参数和30秒超时设置
vim /etc/profile
	# history带时间
	export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami` "
	# 设置 30秒内用户无操作就字段断开终端
	export TMOUT=10

服务器机箱

  • 服务器硬件加封,防止拆机箱;
  • BIOS和管理口加密,防止有人重装系统;
posted @ 2022-03-23 21:27  张贺贺呀  阅读(217)  评论(0编辑  收藏  举报