IT科技

痛心:实验室服务器被挖矿怎么办?

时间:2010-12-5 17:23:32  作者:应用开发   来源:域名  查看:  评论:0
内容摘要:实验室的服务器有比较高的配置,安装了多块显卡,平时实验室的同学主要通过PuTTY、Xshell以及MobaXterm等工具远程访问服务器,上传代码跑实验。过去有段时间,服务器的显卡总是被挖矿程序占用,

实验室的痛心服务器有比较高的配置,安装了多块显卡,实验室服平时实验室的被挖同学主要通过PuTTY、Xshell以及MobaXterm等工具远程访问服务器,矿办上传代码跑实验。痛心过去有段时间,实验室服服务器的被挖显卡总是被挖矿程序占用,学校信息中心的矿办老师告知实验室存在网络攻击行为,实验室因此被临时断网了数天,痛心大家的实验室服科研学习都受到了影响。上述情况重复了好几次,被挖大家逐渐意识到网络安全的矿办重要性,开始探讨增强实验室服务器安全性的痛心方案,致力于让服务器免受网络攻击。实验室服本文主要记录通过一系列配置提高服务器安全性的被挖过程。

更改SSH配置

SSH服务的默认端口是22,是许多端口扫描工具预定义的端口列表中的一项。此外,系统中的亿华云计算常见用户,比如root、admin等,是网络黑客重点关照的对象。通过调整SSH的配置项,更改默认端口,禁止具有执行特权指令的用户远程登录,可以有效提高服务器的安全性。

更改默认端口:22 -> xxxxx

编辑SSH的配置文件”/etc/ssh/sshd_config“,更改默认端口为xxxx(1024~65535区间内的端口):

复制# vi /etc/ssh/sshd_configInclude /etc/ssh/sshd_config.d/*.confPort xxxxx#AddressFamily any#ListenAddress 0.0.0.0#ListenAddress ::1.2.3.4.5.6.7.8.

更改端口后,通过ssh命令登录服务器需要指定端口参数:ssh -p xxxxx username@hostname

禁止root用户登录:”PermitRootLogin no“ 复制# vi /etc/ssh/sshd_config#LoginGraceTime 2mPermitRootLogin no#StrictModes yes#MaxAuthTries 6#MaxSessions 101.2.3.4.5.6.7. 禁止其他用户登录:”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 serverDenyUsers root admin1.2.3.4.5.6.7.8.9. 设置通过密码进行安全验证

SSH提供了两种级别的验证方法:基于口令的安全验证和基于密钥的安全验证。其中,基于密钥的安全验证安全性更高,但由于操作起来比较麻烦(每个用户都要创建一对密钥,需要保管私钥文件),实验室没有采用这一方案。

限制IP访问

通过编辑”/etc/hosts.deny“和”/etc/hosts.allow“两个文件,可以实现限制访问系统的主机的功能(比如限制只能局域网内的主机访问系统)。其中,亿华云”/etc/hosts.allow“中的规则优先级更高,当两个文件中定义的规则冲突时,以”/etc/hosts.allow“中的为准。

1.禁止所有主机通过SSH连接服务器

复制# vi /etc/hosts.deny# You may wish to enable this to ensure any programs that dont# validate looked up hostnames still leave understandable logs. In past# versions of Debian this has been the default

.

# ALL: PARANOIDsshd:ALL1.2.3.4.5.6.7.

2.允许同一网段的主机连接服务器

复制# If youre 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.*:allowsshd:127.0.0.1:allow1.2.3.4.5. 设置Linux-PAM

PAM(Pluggable Authentication Module)是Linux提供的鉴权模块,通过编辑该模块的配置文件”/etc/pam.d/sshd“,可以实现限制SSH尝试登录次数,防止暴力破解的功能。

1.编辑”/etc/pam.d/sshd“

设置SSH尝试登录失败3次后就锁定相应用户1小时(3600秒),用户被锁定期间,哪怕提供了正确的口令,也不能登录系统。注意配置的内容需要加到文件的起始位置。

复制# vi /etc/pam.d/sshd# PAM configuration for the Secure Shell serviceauth required pam_tally2.so deny=3 unlock_time=3600 even_deny_root root_unlock_time=36001.2.3.4.

2.查看被锁定的用户,清除锁定信息

复制# 查看被锁定的用户pam_tally2 -uLogin Failures Latest failure Fromxxx 6 04/17/22 16:25:47 192.168.1.xxx# 清除锁定信息pam_tally2 -r1.2.3.4.5.6.7.8. 开启防火墙

防火墙是另一项能够有效提高系统安全性的技术。实验室主要通过使用”firewall-cmd“命令来配置端口的开放和关闭,做好端口防护工作。由于网上的服务器托管相关资料比较多,这里就不展开介绍了。

查看日志

使用”journalctl“命令可以查看近期登录系统的日志记录:

复制``bashjournalctl -u sshd --since "2022-04-10" | grep passwordApr 12 15:47:32 Zjqgnx903p9xumgkh1cv2Zi sshd[8536]: Failed password for root from 137.184.224.xxx port 50748 ssh2Apr 12 15:47:37 Zjqgnx903p9xumgkh1cv2Zi sshd[8538]: Failed password for root from 137.184.224.xxx port 58468 ssh2Apr 12 15:47:44 Zjqgnx903p9xumgkh1cv2Zi sshd[8540]: Failed password for root from 137.184.224.xxx port 37956 ssh2Apr 12 15:47:49 Zjqgnx903p9xumgkh1cv2Zi sshd[8542]: Failed password for root from 137.184.224.xxx port 45676 ssh2Apr 12 15:47:55 Zjqgnx903p9xumgkh1cv2Zi sshd[8544]: Failed password for root from 137.184.224.xxx port 53396 ssh2Apr 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 ssh2Apr 15 08:36:33 Zjqgnx903p9xumgkh1cv2Zi sshd[13023]: Failed password for invalid user mvr from 165.232.180.xxx port 55306 ssh2Apr 15 08:36:39 Zjqgnx903p9xumgkh1cv2Zi sshd[13025]: Failed password for invalid user ang from 165.232.180.xxx port 34356 ssh2Apr 17 16:49:00 Zjqgnx903p9xumgkh1cv2Zi sshd[17028]: Accepted password for xxx from 221.10.55.xxx port 55762 ssh2```1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.

可以看到有大量尝试登录服务器的记录,做好服务器的安全防护,刻不容缓。

copyright © 2025 powered by 益强资讯全景  滇ICP备2023006006号-31sitemap