美国VPS的系统安全的基本原则,只启动需要的服务,只提供需要的端口访问,关注系统补丁更新
1.更新软件包
centos: yum update -y
debian/ubuntu: apt update && apt upgrade -y
#升级系统小版本
centos: yum upgrade -y
2.设置相对复杂的密码
建议密码包含字母,数字,符号,大小写,以及长度
3.修改默认远程端口
/etc/ssh/sshd_config
Port 22000
systemctl restart sshd
4.防火墙设置
只放行常用的端口,如远程:22000(如果本地公网ip固定,最好设置只允许本地公网ip),web:80,ftp:21
禁用udp端口,只放行请求外部53端口
ubuntu/debian需安装: apt-get install iptables
centos: /etc/sysconfig/iptables
ubuntu: /etc/iptables.rules
debian: /etc/iptables/rules.v4
参考规则:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22000 -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 21 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
-A OUTPUT -p udp -m udp –dport 53 -j ACCEPT
-A OUTPUT -p udp -j DROP
COMMIT
service iptables reload 或者 systemctl reload iptables
debian导入iptables规则: /sbin/iptables-restore < /etc/iptables/rules.v4
5.不提供外部连接的服务监听回环ip
如redis,mysql,elasticsearch,memcache等
示例:
/etc/redis/redis.conf
bind 127.0.0.1
6.关闭系统不需要的服务
列出正在运行的服务: pstree
停止自启:
centos6: chkconfig postfix off
centos7+/debian/ubuntu: systemctl stop postfix ;systemctl disable postfix