centos 7 安全加固脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 7 安全加固脚本相关的知识,希望对你有一定的参考价值。

脚本如下

该脚本采取了多项安全加固措施,包括关闭不必要的服务和端口,禁用文件共享,设置密码复杂度,禁止root用户远程登录,设置超时自动注销等。同时还安装了常用的安全工具,并更新了系统。可以根据需要进行修改和扩展,以适应不同的安全需求。


#!/bin/bash

# 该脚本用于红帽系统的安全加固

# 关闭不必要的服务
systemctl stop abrtd.service
systemctl disable abrtd.service
systemctl stop auditd.service
systemctl disable auditd.service
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service
systemctl stop cups.service
systemctl disable cups.service
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl stop kdump.service
systemctl disable kdump.service
systemctl stop postfix.service
systemctl disable postfix.service
systemctl stop rpcbind.service
systemctl disable rpcbind.service
systemctl stop rsyslog.service
systemctl disable rsyslog.service
systemctl stop sshd.service
systemctl disable sshd.service

# 禁用不必要的网络端口
firewall-cmd --permanent --zone=public --remove-port=2049/tcp
firewall-cmd --permanent --zone=public --remove-port=111/tcp
firewall-cmd --permanent --zone=public --remove-port=111/udp
firewall-cmd --permanent --zone=public --remove-port=32769/tcp
firewall-cmd --permanent --zone=public --remove-port=892/tcp
firewall-cmd --permanent --zone=public --remove-port=2049/udp
firewall-cmd --reload

# 关闭不必要的文件共享
sed -i s/^hosts:.*/hosts: files dns/ /etc/nsswitch.conf

# 设置密码复杂度
sed -i s/^# minlen/minlen/ /etc/security/pwquality.conf
sed -i s/^# dcredit/dcredit/ /etc/security/pwquality.conf
sed -i s/^# ucredit/ucredit/ /etc/security/pwquality.conf
sed -i s/^# lcredit/lcredit/ /etc/security/pwquality.conf
sed -i s/^# ocredit/ocredit/ /etc/security/pwquality.conf

# 禁止root用户远程登录
sed -i s/^#PermitRootLogin yes/PermitRootLogin no/ /etc/ssh/sshd_config

# 设置超时自动注销
echo TMOUT=600 >> /etc/profile
echo export TMOUT >> /etc/profile

# 安装常用的安全工具
yum -y install nmap
yum -y install tcpdump
yum -y install telnet
yum -y install lsof
yum -y install strace
yum -y install curl
yum -y install wget

# 更新系统
yum -y update

如何在CentOS 7中安装,配置和安全加固FTP服务

参考技术A 步骤 1:安装 FTP 服务器

1、 安装 vsftpd 服务器很直接,只要在终端运行下面的命令。

# yum install vsftpd

2、 安装完成后,服务先是被禁用的,因此我们需要手动启动,并设置在下次启动时自动启用:

# systemctl start vsftpd
# systemctl enable vsftpd

3、 接下来,为了允许从外部系统访问 FTP 服务,我们需要打开 FTP 守护进程监听的 21 端口:

# firewall-cmd --zone=public --permanent --add-port=21/tcp
# firewall-cmd --zone=public --permanent --add-service=ftp
还可以使用selinux进行。。

以上是关于centos 7 安全加固脚本的主要内容,如果未能解决你的问题,请参考以下文章

Centos服务器加固安全的脚本

如何在CentOS 7中安装,配置和安全加固FTP服务

Centos 7 安全加固命令行

安全加固-Centos7-Apache

CentOS7 系统服务器初始化配置安全加固内核升级优化常用软件安装的Shell脚本分享

如何在 CentOS 7 中安装配置和安全加固 FTP 服务