Ubuntu root权限下系统安全加固自动化

发布时间:2024-09-24 14:22:23 作者:小樊
来源:亿速云 阅读:78

在Ubuntu root权限下进行系统安全加固,可以通过编写自动化脚本来实现

  1. 更新系统:
apt-get update
apt-get upgrade -y
  1. 移除不必要的服务:
systemctl disable --now cron.daily.service
systemctl disable --now cron.weekly.service
systemctl disable --now cron.monthly.service
  1. 移除不需要的软件包:
apt-get autoremove -y
  1. 删除旧的内核:
apt-get autoremove --purge $(dpkg --list | grep linux-image | grep -v $(uname -r)) -y
  1. 设置密码策略:
chage -d 9999 root
passwd -d root
  1. 禁用root登录:
sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  1. 更改SSH默认端口:
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文件,设置以下参数:
[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. 创建脚本/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. 设置脚本执行权限:
chmod +x /path/to/your/script.sh
  1. 重启Fail2ban服务:
systemctl restart fail2ban
  1. 设置定时任务(如crontab)以定期执行上述安全加固操作。

以上脚本仅为示例,实际应用中可能需要根据具体需求进行调整。在执行任何更改之前,请确保备份重要数据并充分了解每个命令的作用。

推荐阅读:
  1. Ubuntu root权限与文件权限管理
  2. Ubuntu root账户安全加固措施

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ubuntu

上一篇:Ubuntu root权限下系统性能调优实践

下一篇:Ubuntu root账户权限管理审核流程

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》