~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/doc/networking/host-hardening/linux.md -rw-r--r-- 3.6 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago

#Linux Host Hardening

#Kernel Hardening (sysctl)

Config in /etc/sysctl.d/*.conf

#Network

net.ipv4.tcp_syncookies = 1              # SYN flood protection
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.rp_filter = 1          # reverse path filtering (anti-spoofing)
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv6.conf.all.accept_redirects = 0

#Kernel

kernel.randomize_va_space = 2            # full ASLR
kernel.dmesg_restrict = 1               # restrict dmesg
kernel.yama.ptrace_scope = 1            # restrict ptrace
kernel.kptr_restrict = 2                # hide kernel pointers

References:

#systemd Sandboxing

Audit exposure: systemd-analyze security <service>

Key directives:

ProtectSystem=strict       # everything read-only except /dev, /proc, /sys
PrivateTmp=yes             # isolated /tmp namespace
NoNewPrivileges=true       # no privilege escalation
CapabilityBoundingSet=     # restrict Linux capabilities
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
PrivateDevices=yes
RestrictNamespaces=yes
RestrictSUIDSGID=true
IPAddressAllow=            # network access control

References:

#auditd

Kernel-level syscall, file access, auth auditing. Rules in /etc/audit/audit.rules.

Best practice repos:

Expect 10-15% CPU overhead with security-centric config.

#SELinux vs AppArmor

Feature SELinux AppArmor
Model Labels (inode-based) Path-based
Distros RHEL, CentOS, Fedora Debian, Ubuntu
Depth Deeper, system-wide Simpler, application-focused
Weakness Steep learning curve Hard links bypass paths

Both must be in enforcing mode in production. Choose based on distro.

#File Integrity Monitoring

#AIDE / Tripwire

Create baseline snapshots of checksums/permissions/timestamps, detect changes.

  • Monitor /etc and select config dirs, skip /usr (system updates cause legit changes)
  • Combine real-time (auditd) with periodic baseline checks

References:

#CIS Benchmarks & Lynis

CIS: Level 1 (most environments) and Level 2 (high-security). Fresh Ubuntu scores 50s-60s; after Level 1 hardening, 70s-80s.

Lynis: 2000+ config checks, prioritized recommendations.

#SSH Hardening

Core: disable password auth, disable root login, Ed25519 keys, idle timeout, fail2ban.

2025 updates: sntrup761x25519-sha512 in KexAlgorithms, ED25519 host keys prioritized.