linux vps首次使用简单的安全配置。

蜗牛vpsvps教程2021-10-094180

小伙伴们购买完vps第一件事,就是要对服务器做一些基本的配置。保证之后使用的稳定和安全,让我们来介绍一下linux vps首次使用简单的安全配置:


 

1、如果是CentOS7,那默认防火墙是firewalld,另外需要关闭firewall,安装iptables,具体如下:

①关闭firewall:

systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动

②安装防火墙

yum install iptables-services

2、需要修改ssh的端口以及配置iptables防火墙

①用vi编辑/etc/ssh/sshd_config文件

②找到#Port 22一段,这里是标识默认使用22端口,修改为如下:

Port 22Port 50000

然后保存退出

③执行/etc/init.d/sshd restart。现在ssh端口将同时工作与22和50000上(同时两个端口是为了防止发生意外情况导致连不上服务器,等下面测试成功后,在删除22端口)。

④配置iptables

执行脚本

 bash iptables.sh

测试50000端口是否可以正常连接,如果正常则把/etc/ssh/sshd_config中的22端口删除了。

3、禁用root登陆,添加新账户

添加新帐户msa(自己可以指定帐户名)

  [root@kvm7 ~]# useradd msa

设置密码

 [root@kvm7 ~]# passwd msa

修改/etc/ssh/sshd_config文件,禁止使用root用户登陆

vi/etc/ssh/sshd_config

找到#PermitRootLogin yes,去掉前面的#,并将yes改为no,然后重启sshd

service sshd restart

用新建的帐户登陆后,要是需要使用root权限,则使用su root进行切换用户或者sudo后加要执行的命令。

4、安装DDos deflate防御轻量级CC和DDOS,这个主要防止别人恶意请求你的vps。

需要用到iptables,下面命令查看iptables防火墙状态并且确认一下服务器中否安装iptables。

service iptables staus

安装DDos deflate并修改/usr/local/ddos/ddos.conf配置文件,使得iptables可以自己自动锁定ip。

##### Paths of the script and other filesPROGDIR=”/usr/local/ddos”PROG=”/usr/local/ddos/ddos.sh”IGNORE_IP_LIST=”/usr/local/ddos/ignore.ip.list”  //IP地址白名单CRON=”/etc/cron.d/ddos.cron”    //定时执行程序APF=”/etc/apf/apf”IPT=”/sbin/iptables”##### frequency in minutes for running the script##### Caution: Every time this setting is changed, run the script with –cron#####          option so that the new frequency takes effectFREQ=1   //检查时间间隔,默认1分钟##### How many connections define a bad IP? Indicate that below.NO_OF_CONNECTIONS=150     //最大连接数,超过这个数IP就会被屏蔽,一般默认即可##### APF_BAN=1 (Make sure your APF version is atleast 0.96)##### APF_BAN=0 (Uses iptables for banning ips instead of APF)APF_BAN=0        //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)##### KILL=1 (Recommended setting)KILL=1   //是否屏蔽IP,默认即可##### An email is sent to the following address when an IP is banned.##### Blank would suppress sending of mailsEMAIL_TO=admin@zrblog.net   //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱##### Number of seconds the banned ip should remain in blacklist.BAN_PERIOD=600    //禁用IP时间,默认600秒,可根据情况调整

手动设置白名单并不可修改

vi /usr/local/ddos/ignore.ip.list #手工设置白名单IPchattr +i /usr/local/ddos/ignore.ip.list #强制不允许修改chattr -i /usr/local/ddos/ignore.ip.list #解除不允许修改


评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接