当前位置:网站首页>云服务器的安全设置常识
云服务器的安全设置常识
2022-07-02 04:02:00 【一 乐】
1、服务器外置防火墙
服务器安全组,有的叫安全组;有的叫防火墙
2、外置防火墙和内置防火墙
外置防火墙(安全组/防火墙)
内置防火墙(iptables/firewalld)
3、防火墙作用:
防火墙就像一个门,想象一下你的钱藏到你的房间,这时候有一个小偷想要来偷你的钱,小偷需要先溜进你家大门【外置防火墙(安全组/防火墙)】,
然后再溜进你的房间【内置防火墙(iptables/firewalld)】
虽然内置防火墙和外置防火墙一起使用更加安全,但是影响了数据访问的效率了,为了速度,有时候确保安全即可,不用更加安全。
4、购买好服务器,首先设置好外置防火墙
(1) 阿里云服务器:配置放行80、443、ssh端口(ssh端口建议进行修改,不使用默认的22)
(2) 腾讯云服务器:配置放行80、443、ping端口、ssh端口(ssh端口建议进行修改,不使用默认的22)
购买了腾讯云服务的老铁要注意一下:
创建安全组,配置规则的时候,不要选择放行所有端口,要选择自定义
,然后放行80、443、ping、ssh端口
5、修改ssh端口号
修改22端口思路:
先在外置防火墙放行ssh的默认端口22,然后使用xshell远程连接工具进行连接,
然后在配置文件添加22端口、新端口,然后配置成功后,测试新端口可以用后再注释掉配置文件中的22端口,且禁止外置防火墙的22端口
(1) 在外置防火墙放行默认端口号22
(2) 编辑/etc/ssh/sshd_config文件,添加端口号
vim /etc/ssh/sshd_config
- 例如:添加端口22、12345,保存后退出
添加两个端口中保留了22端口的目的:防止可能各种权限和配置问题,可以在测试成功后再关闭22端口
- 新添加的端口号范围建议:大家修改端口时候最好挑10000~65535之间的端口号,10000以下容易被系统或一些特殊软件占用,或是以后新应用准备占用该端口的时候,却被你先占用了,导致软件无法运行。
(3) 重启sshd
- CentOS 7.x 以上系统,执行命令
systemctl restart sshd.service
- CentOS 6.x 以下系统,执行命令
/etc/init.d/sshd restart
(4) 添加防火墙规则,放行端口修改后的端口
- 若是centos7 系统:
举例开放12345端口:
* 开启端口12345: firewall-cmd --zone=public --add-port=12345/tcp --permanent
● 关闭端口12345: firewall-cmd --zone=public --remove-port=12345/tcp --permanent
* 重新加载:让规则生效: firewall-cmd --reload
* 查看 zone=public的端口的信息:firewall-cmd --list-ports --zone=public
- 若是centos6 系统:
# iptables配置文件位置/etc/sysconfig/iptables
# 添加12345端口规则
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 12345 -j ACCEPT
# 保存规则
service iptables save
# 重启服务
service iptables restart
(5) 外置防火墙禁止22端口,添加新配置的端口
(6) 修改xshell的属性中端口号,测试连接成功后,将ssh配置文件的22端口注释掉
- 修改xshell的属性中端口号,测试连接:
- 测试连接成功后,将ssh配置文件的22端口注释掉:
vim /etc/ssh/sshd_config
6、开启防火墙只放行需要的端口的意义
不需要随便向外暴露端口,不然会有安全隐患,总有一大堆机器扫描你的端口,尝试接入你的服务。
尤其像redis端口,有可能会导致你中挖矿病毒;还有ssh端口22,公网中每时每刻都有人通过密码字典暴力破解试图登陆你的服务器。
7、总结使用服务器的安全常识
* 尽量少的对外暴露端口,且尽量修改默认端口号,尽量设置复杂的密码
* 不使用和不安装来源不明的软件
* 及时修复系统提示的漏洞以及软件已知的漏洞
* 定期检查日志
* 安装防病毒软件: 卡巴斯基免费版能抵抗勒索病毒;安装banip软件,错误5次密码,拒绝24小时,防止暴力破解密码;
尽量少的对外暴露端口
首先暴露必须的端口 http(80)、https(443)、ssh端口(不使用默认的)、ping(腾讯服务器需要);其他需要放行的端口,可以考虑使用nginx 进行代理转发
修改默认的端口:
比如mysql 默认端口号是3306,需要使用mysql暴露在外的话,建议修改为mysql的配置文件改为其他端口号;
同理,redis 要在公网使用的话,也是建议修改redis配置文件中端口号为其他端口号,不用默认的6379
设置复杂密码:
可以设置密码的都设置上,且密码不要设置太简单。
比如mysql设置过于弱的密码,也能通过myql织入木马程序;又比如redis放行默认端口6379,然后又不设置redis密码,有可能被植入挖矿程序。
如果本文对你有帮助的话记得给一乐点个赞哦,感谢!
边栏推荐
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
- 蓝桥杯单片机数码管技巧
- Monkey test
- 微信小程序 - 实现获取手机验证码倒计时 60 秒(手机号+验证码登录功能)
- PR zero foundation introductory guide note 2
- The first game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
- Demonstration description of integrated base scheme
- pip 安装第三方库
- Flutter中深入了解MaterialApp,常用属性解析
- Pandora IOT development board learning (HAL Library) - Experiment 2 buzzer experiment (learning notes)
猜你喜欢
蓝桥杯单片机省赛第八届
PR zero foundation introductory guide note 2
[personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
u本位合约爆仓清算解决方案建议
How should the team choose the feature branch development mode or trunk development mode?
集成底座方案演示说明
0基础如何学习自动化测试?按照这7步一步一步来学习就成功了
First acquaintance with P4 language
WPViewPDF Delphi 和 .NET 的 PDF 查看组件
Interface debugging tool simulates post upload file - apipost
随机推荐
Installation et utilisation du lac bleu
PR zero foundation introductory guide note 2
向数据库中存入数组数据,代码出错怎么解决
Which product of anti-cancer insurance is better?
蓝湖的安装及使用
Introduction to vmware workstation and vSphere
整理了一份ECS夏日省钱秘籍,这次@老用户快来领走
Where can I buy cancer insurance? Which product is better?
Fluent icon demo
Opencv learning example code 3.2.4 LUT
Recently, the weather has been extremely hot, so collect the weather data of Beijing, Shanghai, Guangzhou and Shenzhen last year, and make a visual map
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
Basic operations of MySQL database (based on tables)
regular expression
Use of go package
Déchirure à la main - tri
Go branch and loop
Sorted out an ECS summer money saving secret, this time @ old users come and take it away
【IBDFE】基于IBDFE的频域均衡matlab仿真
"No war on the Western Front" we just began to love life, but we had to shoot at everything