当前位置:首页 > 技术教程 > 正文

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

小伙伴们购买完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文件

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

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

Port 22 Port 50000

然后保存退出

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

④配置iptables

执行脚本

bash iptables.sh

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

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

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

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

[root@kvm7 ~]# useraddmsa

设置密码

[root@kvm7 ~]# passwd msa

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

vi/etc/ssh/sshd_config

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

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

service sshd restart

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

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

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

service iptables staus

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

##### Paths of the script and other filesPROGDIR=”/usr/local/分布”PROG=”/usr/local/分布/分布.sh”IGNORE_IP_LIST=”/usr/local/分布/ignore.ip.list” //IP地址白名单CRON=”/etc/cron.d/分布.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/分布/ignore.ip.list #手工设置白名单IP chattr +i /usr/local/分布/ignore.ip.list #强制不允许修改 chattr -i /usr/local/分布/ignore.ip.list #解除不允许修改

以上是关于“虚拟机的硬件配置可以修改吗?”的介绍,如需购买虚拟主机,推荐西西云,共享虚拟主机、独享IP虚拟主机齐备,各类配置均有,满足不同网站建设需求;价格实惠;最低9元/月,提供免费备案,让您快速上线网站。

选购地址:

https://www.kufanyun.com/host/buy.html

0