1.設置會話超時(600代表十分鍾)
vim /etc/profile
生效命令:source /etc/profile
2.新密碼不能與最近10個使用密碼相同
vim /etc/pam.d/system-auth
3.設置禁止root通過ssh遠程登錄
vim /etc/ssh/sshd_config,把#PermitRootLogin yes改為PermitRootLogin no
4.密碼復雜度
默認配置:
cat /etc/pam.d/system-auth | grep "pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=" password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
加固方案:
1.備份配置文件: # cp -a /etc/pam.d/system-auth /etc/pam.d/system-auth.default 2.編輯配置文件 # vi /etc/pam.d/system-auth 將password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
注釋並在其下面新增1行 password requisite pam_cracklib.so try_first_pass minlen=8 difok=5 dcredit=-1 lcredit=-1 ocredit=-1 retry=1 type=
備注:
try_first_pass而當pam_unix驗證模塊與password驗證類型一起使用時,該選項主要用來防止用戶新設定的密碼與以前的舊密碼相同。
minlen=8:最小長度8位
difok=5:新、舊密碼最少5個字符不同
dcredit=-1:最少1個數字
lcredit=-1:最少1個小寫字符,(ucredit=-1:最少1個大寫字符)
ocredit=-1:最少1個特殊字符
retry=1:1次錯誤后返回錯誤信息
type=xxx:此選項用來修改缺省的密碼提示文本
5.設置history密碼時間戳
vim /etc/profile 最底部添加 export HISTTIMEFORMAT="%F %T `whoami` "
效果圖:
6.設置用戶登錄失敗鎖定
# vi /etc/pam.d/system-auth 在# User changes will be destroyed the next time authconfig is run.行的下面,添加 auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root root_unlock_time=1800
7.ssh配置增強
#vi /etc/ssh/sshd_config (1)禁止空密碼登錄 將#PermitEmptyPasswords no參數的注釋符號去掉,改成 PermitEmptyPasswords no (2)關閉ssh的tcp轉發 將#AllowTcpForwarding yes參數改成 AllowTcpForwarding no (3)關閉S/KEY(質疑-應答)認證方式 將#ChallengeResponseAuthentication yes參數,改成 ChallengeResponseAuthentication no (4)關閉基於GSSAPI 的用戶認證 將GSSAPIAuthentication yes參數,改成 GSSAPIAuthentication no 重啟ssh服務
systemctl restart sshd
8.新增連接聲明
#vi /etc/ssh/sshd_config
找到#Banner none參數,在其下一行,增加
Banner /etc/ssh/alert
新增告警信息文件 #vi /etc/ssh/alert 文件內容,設置成 ******************************************************* 這里的內容自己定義,可以提示一下登錄的用戶引起運維人員重視 Warning!!!Any Access Without Permission Is Forbidden!!! *******************************************************
注:ssh設置的可能不支持中文
vim /etc/motd
本人聲明,如果您以非法方式登錄本服務器,您將承擔法律責任!!!
I declare that if you log on this server by illegal means, you will be held legally responsible!!!
效果圖:
9.關閉selinux,清空iptables
關閉selinux防火牆 默認雲服務器都是關着的 cat /etc/selinux/config setenforce 0 設置不啟動 getenforce 查看
清空iptables
# iptables –F #清理防火牆規則 # iptables –L #查看防火牆規則 Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination #/etc/init.d/iptables save #保存防火牆配置信息
針對centos7防火牆配置
修改防火牆 CentOS切換為iptables防火牆 firewall-cmd --state 查看防火牆狀態 切換到iptables首先應該關掉默認的firewalld,然后安裝iptables服務。 1、關閉firewall: systemctl stop firewalld.service systemctl disable firewalld.service #禁止firewall開機啟動 2、安裝iptables防火牆 yum install iptables-services #安裝 service iptables save 3、編輯iptables防火牆配置 vi /etc/sysconfig/iptables #編輯防火牆配置文件 下邊是一個完整的配置文件: 在你運行完save中間插入下面的規則 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited :wq! #保存退出 systemctl start iptables.service #開啟 systemctl enable iptables.service #設置防火牆開機啟動
附贈防火牆腳本,前提你已經切換至iptables
#!/bin/bash
IPT=`which iptables` $IPT -F $IPT -X $IPT -P INPUT DROP $IPT -P FORWARD ACCEPT $IPT -P OUTPUT ACCEPT $IPT -N syn-flood ##本地回環 內網允許任何 $IPT -A INPUT -i lo -j ACCEPT $IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $IPT -A INPUT -m state --state NEW -s 10.0.0.0/8 -j ACCEPT # ssh 端口開放 任何IP $IPT -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT # 根據需求填寫相應的端口 $IPT -A INPUT -p tcp -m multiport --dports 80,8087,89 -j ACCEPT # zabbix監控地址 $IPT -A INPUT -p tcp -s zabbix.ip -m state --state NEW -m tcp --dport 10050 -j ACCEPT # ICMP 規則控制 $IPT -A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT $IPT -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT # DOS防護 $IPT -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood $IPT -A INPUT -j REJECT --reject-with icmp-host-prohibited $IPT -A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN $IPT -A syn-flood -j REJECT --reject-with icmp-port-unreachable
10.鎖定關鍵文件系統
加鎖,不可修改加鎖文件 chattr +i /etc/passwd lsattr /etc/passwd ----i--------e-- /etc/passwd 去鎖,可以修改文件 chattr -i /etc/passwd lsattr /etc/passwd -------------e-- /etc/passwd
使用chattr命令后,為了安全我們需要將其改名
mv /usr/bin/chattr /usr/bin/任意名稱
如果有幫助,請幫忙點個贊吧,謝謝
----------------------致敬每一個正在努力的人