1. 程式人生 > >centos7 系統安全加固方案

centos7 系統安全加固方案

防止 默認 class one crack 遠程登錄 數字 mef alt

一.密碼長度與有效期

默認配置:

[root@i-1y3we23j ~]# cat /etc/login.defs |grep PASS_ |grep -v #
PASS_MAX_DAYS    99999
PASS_MIN_DAYS    0
PASS_MIN_LEN    5
PASS_WARN_AGE    7

加固方案:


1.備份配置文件:

# cp -a /etc/login.defs /etc/login.defs.default

2.編輯配置文件並將相關參數改成如下

# vi /etc/login.defs
PASS_MAX_DAYS 90
PASS_MIN_DAYS 6
PASS_MIN_LEN 
8 PASS_WARN_AGE 30

備註:

/etc/login.defs文件的pass_min_len 參數並不具備強制性,測試仍然可以設置7位密碼。最終需要cracklib來實現。

參數說明:

PASS_MAX_DAYS 密碼有效期

PASS_MIN_DAYS 修改密碼的最短期限

PASS_MIN_LEN 密碼最短長度

PASS_WARN_AGE 密碼過期提醒

二.密碼復雜度

默認配置:

[root@i-1y3we23j ~]# 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= 
3.保存配置文件

備註:

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:此選項用來修改缺省的密碼提示文本

三.新口令不能與4個最近使用的相同

默認配置:

[root@i-1y3we23j ~]# cat /etc/pam.d/system-auth |grep use_authtok
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok

加固方案:

1.備份配置文件
2.編輯配置文件:
# vi /etc/pam.d/system-auth
在password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok 所在行的後面添加
remember=5
3.保存配置文件

備註:

記住5個歷史密碼

四.設置會話超時(5分鐘)

默認配置:

加固方案:

1.備份配置文件:
# cp -a /etc/profile /etc/profile.default
2.編輯配置文件:
vi /etc/profile
在文件的末尾添加參數 
export TMOUT=300
3.保存配置文件

備註:

5分鐘無操作中斷登錄會話

五.設置history命令時間戳

默認配置:

加固方案:

1.備份配置文件:
略
2.編輯配置文件:
vi /etc/profile
在文件的末尾添加參數
export HISTTIMEFORMAT="%F %T `whoami` "
3.保存配置文件

六.設置登陸失敗鎖定(終端登錄)

默認配置:

加固方案:

1.備份配置文件
2.編輯配置文件:
# 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
3.保存配置文件

備註:

通過終端登錄,5次登錄失敗後鎖定賬號30分鐘,鎖定期間此賬號無法再次登錄。

七.禁止root通過ssh遠程登錄

默認配置:

# cat /etc/ssh/sshd_config |grep PermitRootLogin
#PermitRootLogin yes

加固方案:

1.備份配置文件
# cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.default
2.編輯配置文件
vi /etc/ssh/sshd_config
將配置參數#PermitRootLogin yes改成PermitRootLogin no
3.保存配置文件
4.重啟ssh服務
# /etc/init.d/sshd restart

八.SSH 配置參數增強

1.備份配置文件
2.編輯配置文件
#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

3.保存配置文件
4.重啟ssh服務

九.設置SSH登錄警告語

默認配置:

加固方案:

1.備份配置文件
# 略
2.編輯配置文件
#vi /etc/ssh/sshd_config
找到#Banner none參數,在其下一行,增加
Banner /etc/ssh/alert
3.保存配置文件
4新增告警信息文件.
 #vi /etc/ssh/alert
文件內容,設置成
*******************************************************
這裏的內容自己定義,可以提示一下登錄的用戶引起運維人員重視
Warning!!!Any Access Without Permission Is Forbidden!!!
*******************************************************
5.保存後重啟ssh服

十.設置umask值

默認配置:

# umask
0022

加固方案:

1.備份配置文件
# cp -a /etc/bashrc /etc/bashrc.default
2.編輯配置文件
# vi /etc/bashrc
在文件末尾增加參數
umask 027
3.保存配置文件
4. 備份配置文件
# cp -a /etc/profile /etc/pr ofile.default
5.編輯配置文件
# vi /etc/profile
在文件末尾增加參數
umask 027
6.保存配置文件

備註:

umask值設置成0027,用於拿掉新增目錄與文件的非所有者和所有者所屬組的訪問權限

默認:

新增目錄權限755,即rxwr-xr-x

新增文件權限644,即

rw-r--r—

加固後:

新增目錄權限750,即rxwr-x---

新增文件權限640,即

rw-r-----

十一.禁止Control-Alt-Delete 鍵盤重啟系統命令

centos7 系統安全加固方案