返回首页

Linux服务器安全配置手册

注:以CentOS7为例。

一、系统安全

1、系统和软件都升级到最新

yum update -y

2、删除无用的系统账号

userdel games
userdel avahi-autoipd
userdel operator
userdel ftp
userdel saslauth
userdel postfix

3、安装firewalld防火墙

yum install firewalld -y
systemctl start firewalld
systemctl enable firewalld

4、禁用bash历史记录

vi /etc/profile

HISTSIZE=1000

改为:

HISTSIZE=0

然后:

rm ~/.bash_history
history -c

5、安装fail2ban

yum install fail2ban

二、ssh安全配置

1、修改ssh端口号

vi /etc/ssh/sshd_config

#Port 22

前面的#去掉,将默认的22改为你想要的端口号,尽量大于10000,可以大幅度减少被扫描的可能。

2、ssh限制登录IP

vi /etc/ssh/sshd_config

将以下规则添加到文件末尾:

allowusers root@myip1
allowusers root@myip2

3、使用key登录,禁止账号密码登录、禁用root用户登录

vi ~/.ssh/authorized_keys

将用puttykegen生成的pubkey复制到此文件中,一行一个账号。

vi /etc/ssh/sshd_config

#PasswordAuthentication yes

中的#去掉,并改为:

PasswordAuthentication no

#PermitRootLogin yes

中的#去掉,并改为:

PermitRootLogin no

返回首页

版权所有 © 2016-2024 清风的个人笔记