Skip to main content
skill CX Codex

linux-hardening — Claude Code skill: harden Linux servers

A skill that walks your agent through CIS benchmarks: SSH config, user policy, firewall rules and kernel parameters. Useful when a server heads to production or an audit.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill linux-hardening -a claude-code
Open on GitHub

What linux-hardening does

The skill hands your agent ready-made configs and commands for Linux hardening. It covers SSH (no root login, no password auth, a cap on auth attempts), password policy through libpam-pwquality with minlen = 14, locking inactive accounts, and logging sudo to /var/log/sudo.log.

Then come firewall rules for UFW and iptables, kernel settings in /etc/sysctl.d/99-security.conf (redirects off, kernel.randomize_va_space = 2), permissions on files like /etc/shadow, and find commands for world-writable and SUID files. A separate block writes auditd rules that watch /etc/passwd, /etc/shadow and /etc/sudoers.

One thing to know before you run it: these commands change a live system, and ufw enable plus iptables -P INPUT DROP cut incoming traffic right away. Add the SSH rule first or you lock yourself out. Keep console access from your provider handy.

What it helps with

  • close SSH to brute force and root logins
  • set a password policy and account expiry
  • build UFW or iptables rules from scratch
  • bring sysctl values to safe defaults
  • locate world-writable and SUID files

Example prompts for the agent

  • harden SSH following CIS benchmarks
  • check permissions on /etc/shadow and list SUID files
  • write auditd rules to watch changes in /etc/passwd

How to install linux-hardening

1Skills CLI (Vercel)

npx skills add BagelHole/DevOps-Security-Agent-Skills --skill linux-hardening -a claude-code

2Manually: put the files in place

~/.claude/skills/linux-hardening/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/linux-hardening/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about linux-hardening

How do I install linux-hardening in Claude?

Run npx skills add BagelHole/DevOps-Security-Agent-Skills --skill linux-hardening -a claude-code. The skill lands in ~/.claude/skills/linux-hardening/SKILL.md.

What does linux-hardening do?

It gives the agent configs and commands for Linux hardening: SSH, password policy, firewall, kernel parameters, file permissions and auditd rules.

What should I prepare before running it?

Console access to the server. The ufw enable and iptables -P INPUT DROP commands block incoming connections, so the SSH rule has to be in place first.

Source text

SKILL.md · MIT
---
name: linux-hardening
description: Apply CIS benchmarks and secure Linux servers. Configure SSH, manage users, implement firewall rules, and enable security features. Use when hardening Linux systems for production or meeting security compliance requirements.
license: MIT
metadata:
  author: devops-skills
  version: "1.0"
---

# Linux Hardening

Secure Linux servers following CIS benchmarks and security best practices.

## When to Use This Skill

Use this skill when:
- Hardening production servers
- Meeting compliance requirements
- Implementing security baselines
- Configuring secure SSH access

## SSH Hardening

```bash
# /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers deploy admin
Protocol 2
```

## User Security

```bash
# 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
```

## Firewall Configuration

```bash
# 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
```

## Kernel Hardening

```bash
# /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
```

## File Permissions

```bash
# 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
```

## Audit Configuration

```bash
# 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
```

## Best Practices

- Disable unused services
- Keep system updated
- Use fail2ban for intrusion prevention
- Enable SELinux/AppArmor
- Regular security audits
- Monitor log files
- Implement least privilege

## Related Skills

- [cis-benchmarks](../cis-benchmarks/) - Compliance scanning
- [firewall-config](../../network/firewall-config/) - Firewall rules

© devops-skills · MIT · BagelHole/DevOps-Security-Agent-Skills

Similar skills

Everything for Security →

From the same set127

linux-administration A skill for Linux server work: packages, services, disks, processes, cron and logs. Useful when the agent needs to run commands on a server, not just write code. CX Codex +1 770installs docker-management Instructions for building multi-stage Dockerfiles, managing container networks, and troubleshooting failed processes. Useful for container deployment and debugging. CX Codex +1 508installs systemd-services Creates and manages systemd service units, timers, and socket activation. Use it to run background apps and configure resource limits under Linux. CX Codex +1 504installs reverse-proxy Configures nginx and Traefik as reverse proxies for TLS termination, path routing, and rate limiting. CX Codex +1 473installs firewall-config A skill that writes and reviews firewall rules: iptables, nftables, UFW and AWS security groups. Useful when you lock down a server perimeter or split a network into zones. CX Codex +1 458installs ssh-configuration Configures OpenSSH clients and servers, handles Ed25519 keys, port forwarding, and bastion jumps for secure Linux server access. CX Codex +1 451installs prometheus-grafana This skill gives your agent templates for Prometheus scraping, PromQL queries and Grafana panels. Handy when a project needs monitoring added. CX Codex +1 449installs windows-server A skill for Windows Server administration: roles and features, IIS sites, Active Directory users, updates. Useful when the agent touches Windows infrastructure. CX Codex +1 449installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor