Linux系统的VPS安全加固设置
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