新聞中心
實(shí)驗(yàn)室的服務(wù)器有比較高的配置,安裝了多塊顯卡,平時(shí)實(shí)驗(yàn)室的同學(xué)主要通過PuTTY、Xshell以及MobaXterm等工具遠(yuǎn)程訪問服務(wù)器,上傳代碼跑實(shí)驗(yàn)。過去有段時(shí)間,服務(wù)器的顯卡總是被挖礦程序占用,學(xué)校信息中心的老師告知實(shí)驗(yàn)室存在網(wǎng)絡(luò)攻擊行為,實(shí)驗(yàn)室因此被臨時(shí)斷網(wǎng)了數(shù)天,大家的科研學(xué)習(xí)都受到了影響。上述情況重復(fù)了好幾次,大家逐漸意識到網(wǎng)絡(luò)安全的重要性,開始探討增強(qiáng)實(shí)驗(yàn)室服務(wù)器安全性的方案,致力于讓服務(wù)器免受網(wǎng)絡(luò)攻擊。本文主要記錄通過一系列配置提高服務(wù)器安全性的過程。

更改SSH配置
SSH服務(wù)的默認(rèn)端口是22,是許多端口掃描工具預(yù)定義的端口列表中的一項(xiàng)。此外,系統(tǒng)中的常見用戶,比如root、admin等,是網(wǎng)絡(luò)黑客重點(diǎn)關(guān)照的對象。通過調(diào)整SSH的配置項(xiàng),更改默認(rèn)端口,禁止具有執(zhí)行特權(quán)指令的用戶遠(yuǎn)程登錄,可以有效提高服務(wù)器的安全性。
- 更改默認(rèn)端口:22 -> xxxxx
編輯SSH的配置文件”/etc/ssh/sshd_config“,更改默認(rèn)端口為xxxx(1024~65535區(qū)間內(nèi)的端口):
# vi /etc/ssh/sshd_config
Include /etc/ssh/sshd_config.d/*.conf
Port xxxxx
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
更改端口后,通過ssh命令登錄服務(wù)器需要指定端口參數(shù): ssh -p xxxxx username@hostname
- 禁止root用戶登錄:”PermitRootLogin no“
# vi /etc/ssh/sshd_config
#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
- 禁止其他用戶登錄:”DenyUsers root admin“
# vi /etc/ssh/sshd_config
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
DenyUsers root admin
- 設(shè)置通過密碼進(jìn)行安全驗(yàn)證
SSH提供了兩種級別的驗(yàn)證方法:基于口令的安全驗(yàn)證和基于密鑰的安全驗(yàn)證。其中,基于密鑰的安全驗(yàn)證安全性更高,但由于操作起來比較麻煩(每個(gè)用戶都要?jiǎng)?chuàng)建一對密鑰,需要保管私鑰文件),實(shí)驗(yàn)室沒有采用這一方案。
限制IP訪問
通過編輯”/etc/hosts.deny“和”/etc/hosts.allow“兩個(gè)文件,可以實(shí)現(xiàn)限制訪問系統(tǒng)的主機(jī)的功能(比如限制只能局域網(wǎng)內(nèi)的主機(jī)訪問系統(tǒng))。其中,”/etc/hosts.allow“中的規(guī)則優(yōu)先級更高,當(dāng)兩個(gè)文件中定義的規(guī)則沖突時(shí),以”/etc/hosts.allow“中的為準(zhǔn)。
1.禁止所有主機(jī)通過SSH連接服務(wù)器
# vi /etc/hosts.deny
# You may wish to enable this to ensure any programs that don't
# validate looked up hostnames still leave understandable logs. In past
# versions of Debian this has been the default.
# ALL: PARANOID
sshd:ALL
2.允許同一網(wǎng)段的主機(jī)連接服務(wù)器
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
#
sshd:192.168.1.*:allow
sshd:127.0.0.1:allow
設(shè)置Linux-PAM
PAM(Pluggable Authentication Module)是Linux提供的鑒權(quán)模塊,通過編輯該模塊的配置文件”/etc/pam.d/sshd“,可以實(shí)現(xiàn)限制SSH嘗試登錄次數(shù),防止暴力破解的功能。
1.編輯”/etc/pam.d/sshd“
設(shè)置SSH嘗試登錄失敗3次后就鎖定相應(yīng)用戶1小時(shí)(3600秒),用戶被鎖定期間,哪怕提供了正確的口令,也不能登錄系統(tǒng)。注意配置的內(nèi)容需要加到文件的起始位置。
# vi /etc/pam.d/sshd
# PAM configuration for the Secure Shell service
auth required pam_tally2.so deny=3 unlock_time=3600 even_deny_root root_unlock_time=3600
2.查看被鎖定的用戶,清除鎖定信息
# 查看被鎖定的用戶
pam_tally2 -u
Login Failures Latest failure From
xxx 6 04/17/22 16:25:47 192.168.1.xxx
# 清除鎖定信息
pam_tally2 -r
開啟防火墻
防火墻是另一項(xiàng)能夠有效提高系統(tǒng)安全性的技術(shù)。實(shí)驗(yàn)室主要通過使用”firewall-cmd“命令來配置端口的開放和關(guān)閉,做好端口防護(hù)工作。由于網(wǎng)上的相關(guān)資料比較多,這里就不展開介紹了。
查看日志
使用”journalctl“命令可以查看近期登錄系統(tǒng)的日志記錄:
``bash
journalctl -u sshd --since "2022-04-10" | grep password
Apr 12 15:47:32 Zjqgnx903p9xumgkh1cv2Zi sshd[8536]: Failed password for root from 137.184.224.xxx port 50748 ssh2
Apr 12 15:47:37 Zjqgnx903p9xumgkh1cv2Zi sshd[8538]: Failed password for root from 137.184.224.xxx port 58468 ssh2
Apr 12 15:47:44 Zjqgnx903p9xumgkh1cv2Zi sshd[8540]: Failed password for root from 137.184.224.xxx port 37956 ssh2
Apr 12 15:47:49 Zjqgnx903p9xumgkh1cv2Zi sshd[8542]: Failed password for root from 137.184.224.xxx port 45676 ssh2
Apr 12 15:47:55 Zjqgnx903p9xumgkh1cv2Zi sshd[8544]: Failed password for root from 137.184.224.xxx port 53396 ssh2
Apr 12 15:48:01 Zjqgnx903p9xumgkh1cv2Zi sshd[8546]: Failed password for root from 137.184.224.xxx port 32884 ssh2
...
Apr 15 08:36:28 Zjqgnx903p9xumgkh1cv2Zi sshd[13021]: Failed password for invalid user zx from 165.232.180.xxx port 48024 ssh2
Apr 15 08:36:33 Zjqgnx903p9xumgkh1cv2Zi sshd[13023]: Failed password for invalid user mvr from 165.232.180.xxx port 55306 ssh2
Apr 15 08:36:39 Zjqgnx903p9xumgkh1cv2Zi sshd[13025]: Failed password for invalid user ang from 165.232.180.xxx port 34356 ssh2
Apr 17 16:49:00 Zjqgnx903p9xumgkh1cv2Zi sshd[17028]: Accepted password for xxx from 221.10.55.xxx port 55762 ssh2
```
可以看到有大量嘗試登錄服務(wù)器的記錄,做好服務(wù)器的安全防護(hù),刻不容緩。
本文題目:痛心:實(shí)驗(yàn)室服務(wù)器被挖礦怎么辦?
網(wǎng)頁路徑:http://www.dlmjj.cn/article/djgcgip.html


咨詢
建站咨詢
