溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Ubuntu root權(quán)限下系統(tǒng)安全加固自動化

發(fā)布時(shí)間:2024-09-24 14:22:23 來源:億速云 閱讀:78 作者:小樊 欄目:移動開發(fā)

在Ubuntu root權(quán)限下進(jìn)行系統(tǒng)安全加固,可以通過編寫自動化腳本來實(shí)現(xiàn)

  1. 更新系統(tǒng):
apt-get update
apt-get upgrade -y
  1. 移除不必要的服務(wù):
systemctl disable --now cron.daily.service
systemctl disable --now cron.weekly.service
systemctl disable --now cron.monthly.service
  1. 移除不需要的軟件包:
apt-get autoremove -y
  1. 刪除舊的內(nèi)核:
apt-get autoremove --purge $(dpkg --list | grep linux-image | grep -v $(uname -r)) -y
  1. 設(shè)置密碼策略:
chage -d 9999 root
passwd -d root
  1. 禁用root登錄:
sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  1. 更改SSH默認(rèn)端口:
sed -i 's/^Port 22/Port 2222/' /etc/ssh/sshd_config
  1. 安裝Fail2ban:
apt-get install fail2ban -y
  1. 配置Fail2ban: 編輯/etc/fail2ban/jail.d/sshd.conf文件,設(shè)置以下參數(shù):
[sshd]
enabled = true
filter = sshd
logpath = /var/log/auth.log
action = %(action_mwl)s
           your_script[script=/path/to/your/script.sh]
maxretry = 5
findtime = 600
bantime = 600
  1. 創(chuàng)建腳本/path/to/your/script.sh,用于封禁IP地址:
#!/bin/bash
ip=$1
ban_time=600
/usr/bin/iptables -A INPUT -s $ip -j DROP
echo "$ip has been banned for $ban_time seconds." >> /var/log/ban_ip.log
  1. 設(shè)置腳本執(zhí)行權(quán)限:
chmod +x /path/to/your/script.sh
  1. 重啟Fail2ban服務(wù):
systemctl restart fail2ban
  1. 設(shè)置定時(shí)任務(wù)(如crontab)以定期執(zhí)行上述安全加固操作。

以上腳本僅為示例,實(shí)際應(yīng)用中可能需要根據(jù)具體需求進(jìn)行調(diào)整。在執(zhí)行任何更改之前,請確保備份重要數(shù)據(jù)并充分了解每個(gè)命令的作用。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI