当前位置:网站首页>云服务器的安全设置常识
云服务器的安全设置常识
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密码,有可能被植入挖矿程序。
如果本文对你有帮助的话记得给一乐点个赞哦,感谢!
边栏推荐
- [source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
- QT designer plug-in implementation of QT plug-in
- 跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间
- 树莓派GPIO引脚控制红绿灯与轰鸣器
- [untitled]
- Www 2022 | rethinking the knowledge map completion of graph convolution network
- Fingertips life Chapter 4 modules and packages
- Go language naming specification
- Where can I buy cancer insurance? Which product is better?
- 【leetcode】74. Search 2D matrix
猜你喜欢
近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
[personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
Yyds dry inventory compiler and compiler tools
Installation et utilisation du lac bleu
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
Visual slam Lecture 3 -- Lie groups and Lie Algebras
Pandora IOT development board learning (RT thread) - Experiment 1 LED flashing experiment (learning notes)
Sword finger offer II 006 Sort the sum of two numbers in the array
MD5 of Oracle
The 11th Blue Bridge Cup single chip microcomputer provincial competition
随机推荐
蓝桥杯单片机第六届温度记录器
Spring recruitment of Internet enterprises: Kwai meituan has expanded the most, and the annual salary of technical posts is up to nearly 400000
BiShe cinema ticket purchasing system based on SSM
初识P4语言
滴滴开源DELTA:AI开发者可轻松训练自然语言模型
How much is the tuition fee of SCM training class? How long is the study time?
【leetcode】34. Find the first and last positions of elements in a sorted array
Analysis of the overall design principle of Nacos configuration center (persistence, clustering, information synchronization)
微信小程序 - 实现获取手机验证码倒计时 60 秒(手机号+验证码登录功能)
Www 2022 | rethinking the knowledge map completion of graph convolution network
Learn more about materialapp and common attribute parsing in fluent
How to model noise data? Hong Kong Baptist University's latest review paper on "label noise representation learning" comprehensively expounds the data, objective function and optimization strategy of
The 6th Blue Bridge Cup single chip microcomputer provincial competition
树莓派GPIO引脚控制红绿灯与轰鸣器
向数据库中存入数组数据,代码出错怎么解决
Fluent icon demo
The 8th Blue Bridge Cup single chip microcomputer provincial competition
【leetcode】74. Search 2D matrix
go 变量与常量
Vite: configure IP access