基礎優化(linux)

安裝CenTos系統後,給服務器進行基礎優化:

關閉SElinux

SElinux是美國國家安全局NSA對於強制訪問控制的實現

[root@192 ~]# vim /etc/selinux/config 


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@192 ~]# sed -i 's#STLINUX=.*#SELINUX=disabled#g' /etc/selinux/config 
[root@192 ~]# setenforce 0
[root@192 ~]# 


精簡開機系統啓動

linux服務器在運行過程中,會有很多默認的服務在運行,而且這些服務通常是沒用,這些服務佔用了系統資源,存在安全隱患,關閉這些沒用的服務
重要的服務,需要開啓:

1) sshd
遠程連接服務,需要開啓,要不然無法連接linux。
2) rsyslog
是操作系統中提供的一種機制,系統的守護程序通常會使用rsyslog 將各種信息寫到系統日誌文件中,
3) . network
系統啓動時,若想關閉或者激活各個網絡接口,就必須啓動該服務

4) cron
一次性計劃任務: at
週期計劃任務: crontab

5) sysstat
該服務包括監控系統性能及效率的一組工具。這些工具對於收集系統的性能數據很有幫助:核心工具包:
iostat : cpu使用率及硬盤吞吐效率工具
mpstat:提供單個或者多個處理器的數據
sar 負責收集,報告並存儲系統活躍的信息

關閉防火牆

[root@192 ~]# iptables -F
[root@192 ~]# /etc/init.d/iptables stop
iptables:將鏈設置爲政策 ACCEPT:filter                    [確定]
iptables:清除防火牆規則:                                 [確定]
iptables:正在卸載模塊:                                   [確定]
[root@192 ~]# chkconfig iptables off
[root@192 ~]# service iptables stop
[root@192 ~]# 

最小化原則安裝

1 )linux系統最小化安裝,最選包最小化,yum安裝軟件包也要最小化,沒用的包不安裝。
2) 操作系統命令最小化
登錄linux用戶量最小化,不要使用root,使用普通用戶即可
4) 普通授權最小化,即只給必須的管理系統的命令
5)linux系統文件及目錄權限設置最小化,禁止隨便修改,更改,刪除。

更改ssh服務端遠程登錄的配置

1) 端口不要使用22
2) UseDNS no 是否使用DNS,設置爲no之後登錄速度會快
3)#PermitRootLogin no 設置不允許root登錄
4)GSSAPIAuthentication no 解決ssh鏈接慢的問題
5) PasswordAuthentication yes 密碼驗證是必須的,默認yes
PermitEmptyPasswords no 空密碼是否允許登錄
7)#LoginGraceTime 2m 當使用者連接上ssh server的時候,會出現輸入密碼的畫面,在這個畫面中,多久沒有成功連接上就強迫斷線

[root@192 ~]# service sshd restart
停止 sshd:                                                [確定]
正在啓動 sshd:                                            [確定]

[root@192 ~]# ssh 192.168.148.156 [email protected] password:123456
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
[email protected]'s password: 
bash: [email protected]: command not found
[root@192 ~]# 

8) #PrintMotd yes //登入後是否顯示一些信息,比如上次登錄時間,地點。

[root@192 ~]# ssh 192.168.148.156
The authenticity of host '192.168.148.156 (192.168.148.156)' can't be established.
RSA key fingerprint is f0:2c:f5:f3:70:a4:45:b0:e9:bb:9f:ea:fc:76:02:d7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.148.156' (RSA) to the list of known hosts.
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
[email protected]'s password: 
Last login: Fri Mar 13 11:00:47 2020 from 192.168.148.1
[root@192 ~]# 

sudo控制用戶對系統命令的最小化

設置Linux服務器的時間同步

[root@192 ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@192 ~]# 

關於ntp服務

加大服務器文件描述符

[root@192 ~]# vim /etc/security/limits.conf 
[root@192 ~]# ulimit -n
1024
[root@192 ~]# 

禁止 ping

[root@192 ~]# echo 'net.ipv4.icmp_echo_ignore_all = 1' >>/etc/sysctl.conf
[root@192 ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.icmp_echo_ignore_all = 1
[root@192 ~]# 

等等…
https://blog.csdn.net/xinshuzhan/article/details/104694546
https://blog.csdn.net/fanren224/article/details/79971359

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章