linux之Centos7系統(tǒng)加固知識(shí)點(diǎn)小結(jié)

本文主要給大家詳細(xì)介紹了linux中centos7系統(tǒng)加固的相關(guān)知識(shí)點(diǎn),希望能幫助到大家。

注意:此教程的云服務(wù)器以centos7以上為例,云服務(wù)器于阿里云購買

其他服務(wù)商的云服務(wù)器配置大同小異

建議:linux的服務(wù)器不建議安裝圖形化工具,因?yàn)檎純?nèi)存,占帶寬,占資源,弊遠(yuǎn)大于利

手動(dòng)更新系統(tǒng):

yum -y update

防火墻配置:

service firewalld start //啟動(dòng)防火墻
systemctl enable firewalld.service //開機(jī)自啟

selinux配置:

vim /etc/selinux/config

修改:

SELINUX=enforcing //設(shè)置強(qiáng)制模式
reboot //重啟生效

ssh配置:(防暴力破解)

useradd normal //創(chuàng)建一個(gè)系統(tǒng)用戶,設(shè)置只能通過這個(gè)用戶遠(yuǎn)程登錄系統(tǒng)
vim /etc/ssh/sshd_config

修改:

Port 2000 //端口必須大于1024
Protocol 2 //沒有的話就添加,有就不用
PermitEmptyPasswords no //禁止空密碼登錄
X11Forwarding no //禁止端口轉(zhuǎn)發(fā)
PermitRootLogin no //禁止root用戶登錄
MaxAuthTries 3 //允許三次嘗試
LoginGraceTime 20 //在20秒內(nèi)不能完成登錄,則斷開連接
AllowUsers normal //添加,只允許這個(gè)用戶遠(yuǎn)程登錄

保存退出,重啟ssh

service sshd restart

防火墻開啟ssh端口

firewall-cmd –zone=public –add-port=2000/tcp –permanent
firewall-cmd –reload

selinux開啟ssh端口

yum -y install policycoreutils-python //安裝selinux端口管理工具
semanage port -a -t ssh_port_t -p tcp 2000 //添加端口
semanage port -l |grep ssh //查看selinux開啟的ssh端口
service sshd restart

防止IP SPOOF攻擊

vim /etc/host.conf

末尾添加

nospoof on

禁止被ping

vim /etc/sysctl.conf

有則修改,無則添加

net.ipv4.icmp_echo_ignore_all=0

保存配置

sysctl -p

防火墻禁止被ping

firewall-cmd –permanent –add-rich-rule=’rule protocol value=icmp drop’
firewall-cmd –reload

注意:也可以在阿里云控制臺(tái)的安全組規(guī)則,刪除允許ICMP協(xié)議的規(guī)則

每十多天更新一次系統(tǒng),刪除沒有用到的軟件,清除yum緩存

crontab -e

以下內(nèi)容按需修改

0 0 */10 * * yum update -y
0 0 */11 * * yum autoremove -y
0 0 */12 * * yum clean all

防火墻禁止端口掃描(centos7無效,端口還是被掃描出來了,不知道centos7以下是否生效)

iptables -F #清除防火墻策略
iptables -A INPUT -p tcp –tcp-flags ALL FIN,URG,PSH -j Drop
iptables -A INPUT -p tcp –tcp-flags SYN,RST SYN,RST -j Drop
iptables -A INPUT -p tcp –tcp-flags SYN,FIN SYN,FIN -j Drop
iptables -A INPUT -p tcp –tcp-flags SYN,SYN –dport 80 -j Drop

卸載阿里云的云盾(安騎士),因?yàn)榉?wù)器本來就內(nèi)存緊張,云盾弊大于利,卸載

wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod +x uninstall.sh
./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod +x quartz_uninstall.sh
./quartz_uninstall.sh
pkill aliyun-service
rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*

注意:卸載完成后,可以刪除以上兩個(gè)腳本文件。如果無法wget到文件,請(qǐng)聯(lián)系站長索要!

屏蔽云盾IP,云盾會(huì)定期掃描服務(wù)器模擬黑客攻擊

vim shield_ip.sh

添加如下內(nèi)容:

#!/bin/bash
echo “開始屏蔽云盾掃描云服務(wù)器的IP”
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.201.0/28″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.201.16/29″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.201.32/28″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.192/29″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.200/30″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.184/29″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.183/32″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.206/32″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.205/32″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.195/32″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”140.205.225.204/32″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.224.0/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.224.64/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.224.128/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.224.192/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.222.64/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.222.128/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.222.192/26″ drop’
firewall-cmd –permanent –add-rich-rule=’rule family=ipv4 source address=”106.11.223.0/26″ drop’
firewall-cmd –reload

保存退出

chmod +x shield_ip.sh
./shield_ip.sh

注意:這些IP地址段來源于阿里云官方給的云盾服務(wù)器IP,來源:(https://help.aliyun.com/knowledge_detail/37436.html)

編碼設(shè)置:

vim /etc/locale.conf

刪除原有,添加如下內(nèi)容:

LANG=zh_CN.utf8 //中文界面
LC_MESSAGES=en_US.utf8 //英文提示

reboot //重啟生效

進(jìn)入阿里云控制臺(tái),云服務(wù)器ECS–>安全組–>配置規(guī)則–>添加安全組規(guī)則

安全組添加ssh端口,否則外網(wǎng)是無法進(jìn)入的,包括ftp和apache的端口不在安全組開放的話

下載xshell遠(yuǎn)程登錄軟件,normal用戶遠(yuǎn)程登錄至linux系統(tǒng),xshell的使用不再贅述,登錄成功后

su – root //提權(quán)

注意:在阿里云控制臺(tái)遠(yuǎn)程連接登錄系統(tǒng)后,不能以任何用戶一直處于登錄狀態(tài),使用系統(tǒng)完后,必須退出用戶登錄,界面保持在需要輸入用戶名的界面

如:在阿里云控制臺(tái)登錄(而不是xshell登錄),退出用戶登錄命令

logout //exit也可以

注意:root用戶的話必須退出兩次才可以

最后:在阿里云控制臺(tái)–>安全(云盾)–>態(tài)勢感知–>開啟態(tài)勢感知服務(wù)–>設(shè)置郵箱或短信提醒

相關(guān)推薦:

Centos7安裝和配置Mysql5.7的方法分享

Centos7安裝和配置Mysql5.7的方法分享

Centos7安裝和配置Mysql5.7的方法分享

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊14 分享
站長的頭像-小浪學(xué)習(xí)網(wǎng)月度會(huì)員