Hardening_Sever is an Ansible codebase that applies a baseline security posture to Debian/Ubuntu hosts. It exposes a reusable roles:
hardening— OS-level lockdown covering sysctl, PAM, auditd, cron, authentication defaults, filesystem blacklisting, and legacy service removal.
Use the provided playbooks to roll out the baseline to fresh hosts or incorporate the roles into your own automation.
| Path | Description |
|---|---|
ansible.cfg |
Opinionated Ansible defaults (local inventory path, pipelining, host key checking disabled) for faster ad-hoc runs. |
inventory/inventory.yml |
Example inventory targeting the servers group. Replace host definitions with your infrastructure. |
playbooks/hardening.yml |
Entry point that applies the full operating-system hardening role to the servers group. |
roles/hardening/ |
Reusable OS hardening role (tasks, templates, defaults, handlers). |
-
Control node
- Create virtual env
- Ansible 2.12+ (tested with modern releases).
- Python 3.x with
ansible-galaxyavailable. - Create roles with ansible galaxy
-
Managed hosts
- Debian/Ubuntu family (the defaults assume APT,
/etc/login.defs, PAM profiles, etc.). - SSH connectivity with an account that can
become: true(role touches system files). - Package repositories reachable to install baseline packages (e.g.,
auditd,libpam-passwdqc).
- Debian/Ubuntu family (the defaults assume APT,
-
Update the example inventory:
# inventory/inventory.yml all: children: servers: hosts: web01: ansible_host: 192.0.2.10 ansible_user: admin ansible_port: 22
-
(Optional) Test connectivity:
ansible -i inventory/inventory.yml servers -m ping
-
Run the baseline OS hardening:
ansible-playbook -i inventory/inventory.yml playbooks/hardening.yml
Key actions include:
- Refresh package cache, install baseline security packages (
openssh-server,auditd,libpam-modules,libpam-passwdqc), and purge legacy daemons such astelnetd/rsh/xinetd. - Apply kernel/network sysctl defaults sourced from
defaults/main.ymlviatemplates/sysctl-hardening.j2, then triggersysctl --systemreloads. - Lock down scheduled task infrastructure: secure
/etc/cron.*directories, set restrictive permissions on/etc/crontab, removecron.deny/at.deny, and maintaincron.allow/at.allowlists. - Normalize permissions on
/etc/passwd,/etc/group,/etc/shadow,/etc/gshadow. - Configure auditd with opinionated defaults (
templates/auditd.conf.j2) and restart the service when needed. - Enforce PAM password complexity (
templates/pam_passwdqc.j2) and faillock policies (faillockdefaults andcommunity.general.pamdedits). - Manage
/etc/login.defsguardrails (password rotation, retries, UMASK) and disable core dumps through/etc/security/limits.d/hardening.conf. - Set a global
umask 027profile, blacklist uncommon filesystems (templates/filesystems.conf.j2), and ensure handlers reload/restart services as appropriate.
All tunables are exposed in defaults/main.yml; override them in inventory/group vars to adapt to your policy.