Linux SSH 安全加固趴久,這里使用CentOS7.5 做演示
一融蹂、配置SSH雙因素登錄
? 1.確定系統(tǒng)時(shí)鐘是正確的
? 2.安裝相關(guān)依賴
? yum install -y git gcc automake autoconf libtool make pam-devel
? 3.安裝google 驗(yàn)證器
git clone https://github.com/google/google-authenticator-libpam
cd google-authenticator-libpam
./bootstrap.sh
./configure
make && make install
ln -fs /usr/local/lib/security/pam_google_authenticator.so /lib64/security/
? 4.配置驗(yàn)證器
? 修改SSH文件 將ChallengeResponseAuthentication 修改為yes
? 修改PAM文件 vim /etc/pam.d/sshd 在auth substack password-auth下面一行添加 auth required pam_google_authenticator.so
? 關(guān)閉selinux 修改/etc/sysconfig/selinux 文件 將 SELINUX=enforcing 修改為disabled
? google-authenticator
? 重啟SSH服務(wù)
二、設(shè)置密碼長度以及復(fù)雜度
? 1.設(shè)置密碼長度
修改 /etc/login.defs文件
將PASS_MIN_LEN 數(shù)值修改
修改 /etc/pam.d/system_auth配置文件
在password requisite 行后邊添加: minlen=數(shù)值
? 2.設(shè)置密碼復(fù)雜度
方法一:修改/etc/pam.d/system-auth
在password requisite 行后邊添加:
ucredit=-1 #至少包含1位大寫字母
lcredit=-1 #至少包含1位小寫字母
ocredit=-1 #至少包含1位特殊字符
dcredit=-1 #至少包含1位數(shù)字
方法二:使用如下命令:
authconfig --enablereqlower --update
authconfig --enablerequpper --update
authconfig --enablereqdigit --update
authconfig --enablereqother --update
三减响、設(shè)置密碼重試限制
1.限制tty登錄
修改login文件:
# vi /etc/pam.d/login
在#%PAM-1.0下面插入一行脚囊,也就是在第二行插入如下內(nèi)容:
auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root
root_unlock_time=3600
# 注意:上述配置必須在第二行,否則即使用戶被鎖定了芦拿,輸入正確的用戶名和密碼也可以登錄的挟鸠。
# 普通用戶和root用戶,密碼輸入錯(cuò)誤5次币喧,都會被鎖定淮逊,普通用戶被鎖定1800秒,root用戶被鎖定3600秒
# deny=5表示密碼輸入錯(cuò)誤5次
# unlock_time=1800表示普通用戶鎖定的時(shí)間蚁趁,單位為秒
# root_unlock_time=3600表示root用戶鎖定的時(shí)間裙盾,單位為秒
# even_deny_root表示root用戶也鎖定
2.限制ssh登錄
# vi /etc/pam.d/sshd
在#%PAM-1.0下面插入一行,也就是在第二行插入如下內(nèi)容:
auth required pam_tally2.so deny=5 unlock_time=1800 even_deny_root
root_unlock_time=1800
# 注意:上述配置必須在第二行他嫡,否則即使用戶被鎖定了番官,輸入正確的用戶名和密碼也可以登錄的。
要進(jìn)一步了解Linux系統(tǒng)安全加固請點(diǎn)這里钢属!
如有問題徘熔,歡迎指出,謝謝淆党!