上一篇 下一篇 分享链接 返回 返回顶部

Linux系统的VPS安全加固设置

发布人:欢子 发布时间:2026-01-21 15:13 阅读量:10
VPS服务器系统中安全的基本原则,只启动需要的服务,只提供需要的端口访问,关注Linux系统补丁更新

1.更新软件包

centos:yumupdate-y

debian/ubuntu:aptupdate&&aptupgrade-y

#升级系统小版本

centos:yumupgrade-y

2.设置相对复杂的密码

建议密码包含字母,数字,符号,大小写,以及长度

3.修改默认远程端口

/etc/ssh/sshd_config

Port22000

systemctlrestartsshd

4.防火墙设置

只放行常用的端口,如远程:22000(如果本地公网ip固定,最好设置只允许本地公网ip),web:80,ftp:21

禁用udp端口,只放行请求外部53端口

ubuntu/debian需安装:apt-getinstalliptables

centos:/etc/sysconfig/iptables

ubuntu:/etc/iptables.rules

debian:/etc/iptables/rules.v4

参考规则:

*filter

:INPUTACCEPT[0:0]

:FORWARDACCEPT[0:0]

:OUTPUTACCEPT[0:0]

-AINPUT-mstate--stateRELATED,ESTABLISHED-jACCEPT

-AINPUT-picmp-jACCEPT

-AINPUT-ilo-jACCEPT

-AINPUT-ptcp-mstate--stateNEW-mtcp--dport22000-jACCEPT

-AINPUT-ptcp-mstate--stateNEW-mtcp--dport80-jACCEPT

-AINPUT-ptcp-mstate--stateNEW-mtcp--dport21-jACCEPT

-AINPUT-jREJECT--reject-withicmp-host-prohibited

-AFORWARD-jREJECT--reject-withicmp-host-prohibited

-AOUTPUT-pudp-mudp--dport53-jACCEPT

-AOUTPUT-pudp-jDROP

COMMIT

serviceiptablesreload或者systemctlreloadiptables

debian导入iptables规则:/sbin/iptables-restore

5.不提供外部连接的服务监听回环ip

如redis,mysql,elasticsearch,memcache等

示例:

/etc/redis/redis.conf

bind127.0.0.1

6.关闭系统不需要的服务

列出正在运行的服务:pstree

停止自启:

centos6:chkconfigpostfixoff

centos7+/debian/ubuntu:systemctlstoppostfix;systemctldisablepostfix

目录结构
全文