关于 linux-hardening
面向管理员的 Linux 服务器安全加固技能,用于落实 CIS 基准、安全基线或合规要求,涵盖 SSH、账户、防火墙、内核、权限和审计配置。
主要功能
- 01SSH 访问加固
- 02密码策略配置
- 03防火墙规则设置
- 04内核安全参数
- 05文件权限检查
- 06审计规则配置
适用场景
- 01加固生产服务器
- 02落实安全基线
- 03准备满足合规要求
- 04保护 SSH 访问
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ bagelhole/ devops-security-agent-skills --skill linux-hardening安装后在 Claude Code 中输入/linux-hardening确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/ssh-hardening.confsysctl-hardening.confreferences/cis-checklist.mdscripts/audit-system.shharden-system.sh详细介绍
Linux 加固
依据 CIS 基准和安全最佳实践保护 Linux 服务器。
使用此技能的场景
在以下情况下使用此技能:
- 加固生产服务器
- 满足合规要求
- 实施安全基线
- 配置安全的 SSH 访问
SSH 加固
# /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers deploy admin
Protocol 2
用户安全
# Password policy
sudo apt install libpam-pwquality
# /etc/security/pwquality.conf
minlen = 14
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1
# Lock inactive accounts
useradd -D -f 30
# Audit sudo usage
echo "Defaults logfile=/var/log/sudo.log" >> /etc/sudoers
防火墙配置
# UFW setup
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 443/tcp
ufw enable
# Or iptables
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
内核加固
# /etc/sysctl.d/99-security.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
kernel.randomize_va_space = 2
fs.suid_dumpable = 0
# Apply
sysctl -p
文件权限
# Critical files
chmod 600 /etc/shadow
chmod 644 /etc/passwd
chmod 700 /root
chmod 600 /etc/ssh/sshd_config
# Find world-writable files
find / -type f -perm -0002 -ls
# Find SUID files
find / -perm -4000 -type f -ls
审计配置
# Install auditd
apt install auditd
# /etc/audit/rules.d/audit.rules
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/sudoers -p wa -k actions
-a always,exit -F arch=b64 -S execve -k exec
最佳实践
- 禁用未使用的服务
- 保持系统更新
- 使用 fail2ban 防止入侵
- 启用 SELinux/AppArmor
- 定期进行安全审计
- 监控日志文件
- 实施最小权限原则
相关技能
- cis-benchmarks - 合规扫描
- firewall-config - 防火墙规则
评论
支持 Markdown