30+ Linux Hardening Steps in Order

Author: JJustis | Published: 2025-08-17 03:33:19
Article Image 1

30 Linux Hardening Techniques: From Standard to Fabulous

Complete Security Hardening Guide for Modern Linux Systems

⚡ Security Level Classifications:
  • Standard: Essential techniques every admin should implement
  • Advanced: Techniques for high-security environments
  • Rare: Cutting-edge and specialized hardening methods
  • Fabulous: Obscure but powerful security enhancements

  • Kernel & System Hardening

    1. Modern Kernel Address Space Layout Randomization (KASLR)
    Level: Standard
    Enable advanced ASLR with new kernel parameters for better memory randomization:

    /etc/sysctl.d/99-hardening.conf:
  • kernel.randomize_va_space = 2
  • kernel.kptr_restrict = 2
  • kernel.dmesg_restrict = 1
  • kernel.unprivileged_bpf_disabled = 1

  • 2. Control Flow Integrity (CFI) Protection
    Level: Advanced
    Enable Intel CET (Control-flow Enforcement Technology) and ARM Pointer Authentication:

  • kernel.yama.ptrace_scope = 3
  • kernel.core_uses_pid = 1
  • kernel.ctrl_alt_del = 0
  • fs.suid_dumpable = 0

  • 3. Memory Protection with SMEP/SMAP
    Level: Advanced
    Supervisor Mode Execution Prevention and Supervisor Mode Access Prevention:

  • Add to GRUB_CMDLINE_LINUX: "smep smap"
  • kernel.exec-shield = 1
  • kernel.randomize_va_space = 2

  • 4. Kernel Guard Technology
    Level: Rare
    Enable Intel Kernel Guard (KG) and Control Flow Guard (CFG):

  • Add to kernel cmdline: "kg_protection=1 cfg_protection=1"
  • kernel.hardened_usercopy = 1
  • kernel.kexec_load_disabled = 1

  • Network Security Hardening

    5. Advanced TCP/IP Stack Hardening
    Level: Standard
    Comprehensive network stack protection:

  • net.ipv4.tcp_syncookies = 1
  • net.ipv4.tcp_rfc1337 = 1
  • net.ipv4.tcp_timestamps = 0
  • net.ipv4.tcp_sack = 0
  • net.ipv4.tcp_dsack = 0
  • net.ipv4.tcp_fack = 0

  • 6. IPv6 Privacy Extensions Plus
    Level: Advanced
    Enhanced IPv6 privacy and security:

  • net.ipv6.conf.all.use_tempaddr = 2
  • net.ipv6.conf.default.use_tempaddr = 2
  • net.ipv6.conf.all.temp_prefered_lft = 86400
  • net.ipv6.conf.all.temp_valid_lft = 172800
  • net.ipv6.conf.all.max_desync_factor = 600

  • 7. Network Namespace Isolation
    Level: Advanced
    Create isolated network namespaces for critical services:

  • ip netns add secure-ns
  • ip netns exec secure-ns systemctl start your-service
  • echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  • echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

  • 8. Advanced Firewall with nftables
    Level: Rare
    Next-generation packet filtering with stateful inspection:

  • table inet filter {
  • chain input {
  • type filter hook input priority 0; policy drop;
  • ct state invalid drop
  • ct state {established, related} accept
  • meta l4proto icmp limit rate 4/second accept
  • }
  • }

  • File System & Storage Hardening

    9. Advanced File System Attributes
    Level: Standard
    Protect critical files with extended attributes:

  • chattr +i /etc/passwd /etc/shadow /etc/group
  • chattr +a /var/log/auth.log
  • chattr +u /home/*/important-files
  • lsattr /etc/passwd (verify attributes)

  • 10. LUKS2 with Argon2 Key Derivation
    Level: Advanced
    Modern disk encryption with enhanced key stretching:

  • cryptsetup luksFormat --type luks2 --pbkdf argon2id --pbkdf-memory 1048576 /dev/sdX
  • cryptsetup luksAddKey --pbkdf argon2id --pbkdf-force-iterations 4 /dev/sdX

  • 11. ZFS Encryption with Native Encryption
    Level: Rare
    Dataset-level encryption with ZFS native features:

  • zfs create -o encryption=aes-256-gcm -o keyformat=passphrase rpool/encrypted
  • zfs set compression=lz4 rpool/encrypted
  • zfs set dedup=sha256 rpool/encrypted

  • 12. Filesystem Integrity Monitoring (FIM)
    Level: Advanced
    Real-time file integrity monitoring with inotify:

  • auditctl -w /etc -p wa -k etc_changes
  • auditctl -w /bin -p x -k binary_execution
  • auditctl -w /sbin -p x -k sbin_execution
  • auditctl -w /usr/bin -p x -k usr_bin_execution

  • Process & Memory Hardening

    13. Process Isolation with Landlock LSM
    Level: Rare
    Application-level sandboxing with the newest Linux Security Module:

  • Add to kernel cmdline: "lsm=landlock,lockdown,yama,apparmor"
  • Enable landlock for applications: LL_FS_REFER | LL_FS_MAKE_REG

  • 14. Memory Tagging and Pointer Authentication
    Level: Fabulous
    ARM64 Memory Tagging Extensions (MTE) and Pointer Authentication:

  • Add to kernel cmdline: "arm64.mte=sync"
  • echo always > /sys/kernel/mm/transparent_hugepage/enabled
  • echo madvise > /sys/kernel/mm/transparent_hugepage/defrag

  • 15. Intel CET (Control-flow Enforcement Technology)
    Level: Fabulous
    Hardware-assisted control flow integrity:

  • Add to kernel cmdline: "cet=on"
  • export GLIBC_TUNABLES=glibc.cpu.hwcaps=-CET
  • gcc -fcf-protection=full -o program program.c

  • 16. Process Capability Dropping
    Level: Advanced
    Fine-grained privilege control with capabilities:

  • setcap cap_net_bind_service=+ep /usr/bin/python3
  • getcap /usr/bin/python3
  • capsh --drop=cap_sys_admin --

  • AppArmor & MAC Hardening

    17. Advanced AppArmor Profiles
    Level: Advanced
    Comprehensive application confinement:

  • aa-genprof /usr/bin/your-app
  • aa-logprof (after running the application)
  • aa-enforce /etc/apparmor.d/usr.bin.your-app
  • aa-status (verify active profiles)

  • 18. AppArmor Network Rules
    Level: Rare
    Network access control within AppArmor profiles:

  • network inet tcp,
  • network inet udp,
  • network unix stream,
  • deny network raw,
  • deny network packet,

  • 19. AppArmor Mount Rules
    Level: Rare
    Filesystem mount restrictions:

  • deny mount,
  • deny umount,
  • mount options=(ro, noexec) /tmp/ -> /var/tmp/,
  • mount fstype=tmpfs -> /tmp/,

  • 20. AppArmor Signal Rules
    Level: Fabulous
    Inter-process communication control:

  • signal (send) set=(term, kill) peer=/usr/bin/target,
  • signal (receive) set=(term) peer=unconfined,
  • deny signal (send) set=(kill) peer=@{profile_name},

  • Boot & Secure Boot Hardening

    21. UEFI Secure Boot with Custom Keys
    Level: Advanced
    Custom PKI for secure boot chain:

  • openssl req -new -x509 -newkey rsa:2048 -keyout PK.key -out PK.crt
  • efi-updatevar -f PK.esl PK
  • sbsign --key db.key --cert db.crt --output vmlinuz.signed vmlinuz

  • 22. Intel Boot Guard
    Level: Rare
    Hardware-based boot integrity verification:

  • Configure in BIOS: Enable Boot Guard
  • Verify: dmesg | grep -i "boot guard"
  • Check TPM PCR values: tpm2_pcrread

  • 23. AMD Secure Memory Encryption (SME)
    Level: Fabulous
    System memory encryption at hardware level:

  • Add to kernel cmdline: "mem_encrypt=on"
  • Verify: dmesg | grep -i "memory encryption"
  • Check: cat /sys/kernel/mm/amd_sme/sme_enabled

  • Logging & Monitoring Hardening

    24. Advanced Auditd Configuration
    Level: Standard
    Comprehensive system call auditing:

  • auditctl -a always,exit -F arch=b64 -S execve -k exec_commands
  • auditctl -a always,exit -F arch=b64 -S openat -F success=0 -k file_access_failures
  • auditctl -w /etc/sudoers -p wa -k sudoers_changes
  • auditctl -w /var/log/wtmp -p wa -k login_logout

  • 25. Real-time Security Monitoring with eBPF
    Level: Rare
    Kernel-level security monitoring with extended Berkeley Packet Filter:

  • bpftrace -e 'tracepoint:syscalls:sys_enter_execve { printf("PID %d executed %s\n", pid, str(args->filename)); }'
  • bpftrace -e 'kprobe:tcp_connect { printf("TCP connection from PID %d\n", pid); }'

  • 26. Kernel Runtime Security Monitoring (KRSI)
    Level: Fabulous
    eBPF-based Linux Security Module:

  • Add to kernel cmdline: "lsm=krsi,apparmor"
  • Load KRSI programs: bpf_prog_load(BPF_PROG_TYPE_LSM, ...)

  • Service & Application Hardening

    27. Systemd Security Features
    Level: Advanced
    Modern service isolation with systemd:

  • [Service]
  • PrivateNetwork=yes
  • PrivateTmp=yes
  • PrivateDevices=yes
  • ProtectSystem=strict
  • ProtectHome=yes
  • NoNewPrivileges=yes
  • ProtectKernelTunables=yes
  • ProtectKernelModules=yes
  • ProtectControlGroups=yes
  • RestrictRealtime=yes
  • RestrictSUIDSGID=yes
  • LockPersonality=yes
  • MemoryDenyWriteExecute=yes
  • RestrictNamespaces=yes

  • 28. User Namespace Sandboxing
    Level: Rare
    Application isolation with user namespaces:

  • unshare -U -r /bin/bash
  • echo 'deny' > /proc/sys/kernel/unprivileged_userns_clone
  • sysctl kernel.unprivileged_userns_clone=0

  • 29. Intel MPX (Memory Protection Extensions)
    Level: Fabulous
    Hardware-assisted bounds checking (deprecated but educational):

  • gcc -fcheck-pointer-bounds -mmpx -o program program.c
  • Add to kernel cmdline: "nompx" (to disable if causing issues)

  • 30. Hardware Security Modules (HSM) Integration
    Level: Fabulous
    TPM 2.0 and PKCS#11 integration for key management:

  • tpm2_createprimary -C o -g sha256 -G rsa -c primary.ctx
  • tpm2_create -C primary.ctx -g sha256 -G aes -r key.priv -u key.pub
  • tpm2_load -C primary.ctx -r key.priv -u key.pub -c key.ctx
  • tpm2_encryptdecrypt -c key.ctx -o encrypted.dat plaintext.dat

  • Implementation Priority Matrix

    Priority Techniques Complexity Impact
    P0 - Critical 1, 5, 9, 17, 24 Low-Medium High
    P1 - High 2, 6, 10, 16, 18, 21, 27 Medium High
    P2 - Medium 3, 7, 11, 12, 19, 22, 25, 28 Medium-High Medium-High
    P3 - Advanced 4, 8, 13, 20, 23, 26, 29, 30 High Medium
    Research - Cutting Edge 14, 15 Very High Future-Proof

    Verification & Testing

    Security Validation Commands:

  • sysctl -a | grep -E "(randomize|kptr|dmesg)" (verify kernel hardening)
  • aa-status (check AppArmor profiles)
  • systemctl status auditd (verify audit daemon)
  • lsattr /etc/passwd (check file attributes)
  • netstat -tuln (verify listening services)
  • ss -tuln (modern netstat alternative)
  • iptables -L -n (check firewall rules)
  • mount | grep -E "(noexec|nodev|nosuid)" (verify mount options)
  • journalctl -u your-service --no-pager (check service logs)
  • tpm2_getcap properties-fixed (verify TPM status)

  • Security Testing Tools:
  • lynis audit system (comprehensive security audit)
  • chkrootkit (rootkit detection)
  • rkhunter --check (rootkit hunter)
  • tiger (security auditing tool)
  • aide --check (file integrity checking)

  • Final Recommendations

    Implementation Strategy:

  • Phase 1: Implement Standard techniques (1-2 weeks)
  • Phase 2: Deploy Advanced techniques (3-4 weeks)
  • Phase 3: Rare techniques for high-security environments (1-2 months)
  • Phase 4: Fabulous techniques for cutting-edge security (ongoing)

  • Remember: Security hardening is an ongoing process. Regularly review and update your security posture as new threats and techniques emerge. Test all changes in a development environment before applying to production systems.

    Critical Warning: Some advanced techniques may impact system performance or compatibility. Always benchmark and test thoroughly before production deployment.

    Last updated: July 24, 2025 | Classification: Technical Reference | Distribution: Internal Use