安全加固
- SSH連接
Secure Shell(安全外殼協(xié)議,簡(jiǎn)稱SSH)是一種加密的網(wǎng)絡(luò)傳輸協(xié)議,可在不安全的網(wǎng)絡(luò)中為網(wǎng)絡(luò)服務(wù)提供安全的傳輸環(huán)境。SSH通過(guò)在網(wǎng)絡(luò)中創(chuàng)建安全隧道來(lái)實(shí)現(xiàn)SSH客戶端與服務(wù)器之間的連接。雖然任何網(wǎng)絡(luò)服務(wù)都可以通過(guò)SSH實(shí)現(xiàn)安全傳輸,SSH最常見的用途是遠(yuǎn)程登錄系統(tǒng),人們通常利用SSH來(lái)傳輸命令行界面和遠(yuǎn)程執(zhí)行命令。使用頻率最高的場(chǎng)合類Unix系統(tǒng),但是Windows操作系統(tǒng)也能有限度地使用SSH。
SSH本身是一個(gè)非常安全的認(rèn)證連接方式。不過(guò)由于人過(guò)等方面的原因,難免會(huì)造成密碼的泄露。針對(duì)這種問(wèn)題我們不妨給SSH再加一把鎖。當(dāng)然,增加這層鎖的方式有很多種。例如:knockd、S/KEY、OPIE/OPTW、Two-factor authentication等。
- Google Authenticator
Google身份驗(yàn)證器是一款基于時(shí)間與哈希的一次性密碼算法的兩步驗(yàn)證軟件令牌,此軟件用于Google的認(rèn)證服務(wù)。此項(xiàng)服務(wù)所使用的算法已列于 RFC 6238 和 RFC 4226 中。
Google身份驗(yàn)證器給予用戶一個(gè)六位到八位的一次性密碼用于進(jìn)行登錄Google或其他站點(diǎn)時(shí)的附加驗(yàn)證。其同樣可以給第三方應(yīng)用生成口令,例如密碼管家程序或網(wǎng)絡(luò)硬盤。先前版本的Google身份驗(yàn)證器開放源代碼,但之后的版本以專有軟件的形式公開。
3.Linux 中安裝
3.1 系統(tǒng)環(huán)境說(shuō)明
[root@tts.morekey.cn /root]
cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@tts.morekey.cn /root]
uname -a
Linux clsn.io 4.10.5-1.el6.elrepo.x86_64 #1 SMP Wed Mar 22 14:55:33 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@tts.morekey.cn /root]
sestatus
SELinux status: disabled
3.2 安裝 Google Authenticator
3.2.1 安裝依賴包
yum -y install wget gcc make pam-devel libpng-devel
3.2.2 Google Authenticator PAM插件安裝
可在google的github下載
wget https://github.com/google/google-authenticator/archive/1.02.tar.gz
tar xf 1.02.tar.gz
cd google-authenticator-1.02/libpam/
./bootstrap.sh
./configure
make && make install
安裝完成后會(huì)在 /usr/local/lib/security/pam_google_authenticator.so
生成一個(gè) 庫(kù)文件,
系統(tǒng)還會(huì)多在/usr/local/bin目錄生成一個(gè)google-authenticator可執(zhí)行文件,通過(guò)運(yùn)行該命令進(jìn)行配置。
3.2.3 復(fù)制so文件
# cp /usr/local/lib/security/pam_google_authenticator.so /lib64/security/
- 配置 SSH + Google Authenticator
4.1 初始配置 Google Authenticator
[root@tts.morekey.cn /lib64/security]
#google-authenticator
Do you want authentication tokens to be time-based (y/n) n
# 是否基于時(shí)間的認(rèn)證,為了防止不同跨時(shí)區(qū)的問(wèn)題,這里選擇n
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://hotp/root@clsn.io%3Fsecret%3*****%26issuer%3Dclsn.io
# s生成的二維碼
Your new secret key is: ****
Your verification code is 5****0
Your emergency scratch codes are:
40****84
19****95
60****78
83****92
31****58
# 這5個(gè)碼用于在取不到或錯(cuò)的驗(yàn)證碼有錯(cuò)時(shí),用于應(yīng)急用的。不過(guò)每個(gè)只能用一次,不能重復(fù)使用。
Do you want me to update your "/root/.google_authenticator" file? (y/n) y
By default, three tokens are valid at any one time. This accounts for
generated-but-not-used tokens and failed login attempts. In order to
decrease the likelihood of synchronization problems, this window can be
increased from its default size of 3 to 17. Do you want to do so (y/n) y
If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) y
4.2 SSH調(diào)用及客戶端配置
添加pam認(rèn)證,在第一行添加
# vim /etc/pam.d/sshd
auth required pam_google_authenticator.so
------------------------------------------------------------------
#cat /etc/pam.d/sshd
#%PAM-1.0
auth required pam_sepermit.so
auth required pam_google_authenticator.so
auth include password-auth
account required pam_nologin.so
account include password-auth
password include password-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open env_params
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include password-auth
修改sshd配置
# vim /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
#把上面配置改成
重啟 sshd 服務(wù)
# service sshd restart