Amazon Linux 2023 ships with stronger defaults than Amazon Linux 2, but several of the controls that matter most, including SELinux enforcement and kernel live patching, are switched off or set to observe only until you change them. This guide sets out how to build a hardened AL2023 baseline for EC2 fleets: moving SELinux from permissive to enforcing, enabling kernel live patching without losing track of reboots, controlling package updates with versioned repositories, tightening SSH and metadata access, and proving the baseline holds over time.
It focuses on what is specific to AL2023. General Linux server controls such as PAM, sudo, sysctl and auditd rules are covered in the Linux Server Hardening Guide, and instance-level AWS controls in the Amazon EC2 Security Guide.
This is an independent guide from NHI Mgmt Group, based on AWS's public documentation as of November 2026. It is not sponsored or reviewed by AWS. Product features change, so confirm settings against AWS's current documentation.
Key takeaways
- Amazon Linux 2 reached end of support on 30 June 2026, so any remaining AL2 instance is now running without security updates. AWS states AL2023 is supported until June 2029.
- SELinux on AL2023 is enabled but in permissive mode by default: denials are logged, not enforced. Moving to enforcing is the single biggest hardening step and needs a tested rollout.
- Kernel live patching is disabled by default. Once enabled, AWS provides live patches for a given kernel version for up to three months, so live patching reduces reboots but never removes them.
- AL2023 does not install security updates at launch by default. Updates are tied to a repository version (releasever), which gives you deterministic, testable patching if you manage it deliberately.
- OpenSSH 8.7 disables the ssh-rsa algorithm by default. Old clients and automation that rely on it will break, which is a good prompt to retire them rather than re-enable it.
- Treat the instance role and the metadata service as a non-human identity. Hardening the operating system does little if any process on the host can read role credentials through an unprotected metadata endpoint.
Why AL2023 needs its own baseline
Many teams carried their Amazon Linux 2 hardening scripts across to AL2023 and assumed they still applied. Several of the underlying components changed, so some of those scripts now do nothing and others actively fail. AWS's comparison of AL2 and AL2023 lists the changes that most affect a hardening baseline:
- DNF replaces YUM as the package manager.
- The systemd journal replaces rsyslog as the default logging system, and systemd timers replace cron.
- systemd-networkd manages network interfaces instead of dhclient.
- /tmp is now a tmpfs, the unified cgroup v2 hierarchy is used, and UEFI with Secure Boot is the preferred boot mode.
- SELinux, which was disabled in AL2, is now enabled in permissive mode.
- No 32-bit userspace packages are shipped.
- cloud-init now fails closed: if a remote resource referenced at launch is unavailable, the cloud-init run fails rather than continuing silently.
Each of these has a hardening consequence. A CIS-style rule that checks rsyslog configuration will pass or fail on an AL2023 host for reasons unrelated to whether logs are actually shipped. A cron hardening rule says nothing about systemd timers, which is where scheduled jobs now live. Rewrite your baseline against AL2023 rather than porting it. If you use the CIS Benchmarks Guide approach, make sure you are using the benchmark written for AL2023, not the AL2 or generic RHEL benchmark.
Moving SELinux from permissive to enforcing
AWS describes SELinux on AL2023 as enabled and set to permissive mode by default, where permission denials are logged but not enforced. The policies are targeted or multi-level security (MLS). Permissive mode is useful as a learning phase, but on its own it provides no protection: a compromised web service can still read files outside its context, and the only evidence is a log entry.
Check the current state
Run getenforce on a sample of instances. A fresh AL2023 host returns Permissive. Record this across the fleet before you start, because the result tells you which hosts have never been changed.
Collect denials while still permissive
Run your real workload in permissive mode for long enough to exercise every code path: deployments, backups, log rotation, monitoring agents and any scheduled job. Then review what SELinux would have blocked. AWS documents this command for viewing denied actions:
sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent
Group the results by process and target type. Most denials on a well-packaged system come from three sources: application files placed in unusual paths without the right file context, services listening on non-standard ports, and third-party agents that were never written with SELinux in mind. Fix the first two by relabelling files and assigning port types, not by writing broad custom policy. Treat agents as a vendor question: ask for an SELinux policy module or confirmation that the agent supports enforcing mode.
Switch to enforcing
AWS documents two methods. For running instances, edit /etc/selinux/config so the line reads SELINUX=enforcing, then reboot. For new instances, set the mode at launch through cloud-init user data:
#cloud-configselinux: mode: enforcing
By default this causes the instance to reboot, which AWS recommends for stability. A selinux_no_reboot: 1 option exists to skip the reboot, but a reboot gives you a clean, fully labelled state. AWS notes that on the next boot SELinux relabels all files and directories, including those created while SELinux was disabled, so allow extra time for that first boot on large volumes.
Roll out in rings
Do not flip the whole fleet at once. A sensible order is: build pipelines and golden images first, then a canary group of each workload, then the rest by environment. Keep a documented rollback (set permissive, reboot) and a time limit on any host that is reverted, so permissive mode does not become permanent by default. Track the percentage of instances reporting Enforcing as a fleet metric.
Kernel live patching without losing track of reboots
Kernel Live Patching applies security and critical bug fixes to a running kernel without rebooting. AWS states it is provided at no additional cost and is disabled by default on AL2023. It is available on 64-bit x86_64 and ARM64 for the 6.1, 6.12 and 6.18 kernel versions, on EC2 and on-premises virtual machines running AL2023.
Enabling it
The documented sequence installs the DNF plugin, enables automatic live patch installation and starts the kpatch service:
sudo dnf install -y kpatch-dnfsudo dnf kernel-livepatch -y autosudo dnf install -y kpatch-runtimesudo systemctl enable kpatch.service && sudo systemctl start kpatch.service
Apply available security patches with sudo dnf upgrade --security and confirm what is loaded with sudo kpatch list. For fleets, AWS points to Systems Manager rather than per-host commands; see the AWS Systems Manager Security Guide for how to keep the automation role itself tightly scoped.
Know the limits
Three limits shape how you use live patching:
- Coverage is best effort. AWS states security updates are typically for CVEs rated important or critical, and not every critical CVE gets a live patch. Some fixes are only delivered in the full kernel package.
- The window is short. AWS provides live patches for a kernel version for up to three months after its release. After that you must reboot into a newer kernel to keep receiving them. Check each host with
sudo dnf kernel-livepatch support. - It affects tooling. While a live patch is applied you cannot hibernate, use some advanced debugging tools such as SystemTap, kprobes and eBPF-based tools, or access the ftrace output files used by the live patching infrastructure. Check this against your runtime security and observability agents, several of which rely on eBPF. The eBPF Security Guide covers why those agents matter.
The practical model is to use live patching to close the gap between a kernel CVE being published and your next maintenance window, and to keep a reboot cadence shorter than the three-month support window. A host that has been live patched for four months is no longer protected, even though kpatch list still shows patches.
Deterministic updates and versioned repositories
In earlier Amazon Linux versions, cloud-init installed security updates at launch. AWS states this is not the default for AL2023. Instead, AL2023 ties packages to a repository version and offers deterministic upgrade features that let you set the releasever at launch.
This is a security improvement if you use it, and a gap if you do not. The benefit is that every instance launched from the same image and release version has exactly the same package set, which makes testing, rollback and vulnerability scanning meaningful. The risk is that an instance launched from an old image keeps the old package set indefinitely unless something moves it forward.
A workable model:
- Build golden images on a fixed schedule, each pinned to the latest repository version at build time, and record that version as an image tag.
- Scan images before release with your vulnerability scanner and block release when critical findings have a fix available.
- For long-lived instances, move them to a new release version through your patching tool, test, and then apply
dnf upgrade --securityagainst that version. - Set a maximum age for images and for the release version on running hosts, and alert when it is exceeded.
Because cloud-init now fails closed when a remote resource is unavailable, launch-time scripts that pull packages or configuration from a repository will stop rather than continue half-configured. Treat that as a feature: it prevents an instance joining a load balancer with an incomplete baseline. Make sure your launch templates and Auto Scaling health checks handle the failure cleanly.
SSH, cryptography and remote access
AWS states that AL2023 includes OpenSSH 8.7, which disables the ssh-rsa algorithm by default, and OpenSSL 3. Both changes break some older automation, and both are worth keeping.
- Do not re-enable ssh-rsa. If an old configuration management tool, jump host or network device fails to connect, upgrade it or move it to a modern key type. Re-enabling the algorithm fleet-wide to fix one integration weakens every host.
- Prefer no inbound SSH at all. Use Systems Manager Session Manager or EC2 Instance Connect for interactive access, with access governed through IAM and logged centrally. If SSH must stay, restrict it to a bastion or VPN range by security group, disable password authentication and root login, and use short-lived certificates rather than long-lived keys copied between people.
- Audit OpenSSL 3 dependencies. Applications built against older OpenSSL versions may need rebuilding. Check that they do not fall back to bundled, unpatched libraries.
- Set crypto policy deliberately. If you need FIPS mode or a stricter system-wide policy, follow the process in the Linux System-Wide Crypto Policies and FIPS Mode Guide and confirm AL2023 specifics in AWS's current documentation before relying on it for compliance.
SSH keys and host keys are non-human credentials. Inventory them, give each an owner, and remove keys from authorized_keys when people or pipelines no longer need them. Golden images should not contain any authorised keys beyond what your access model requires.
The instance role and metadata service
An AL2023 host is only as secure as the credentials it can reach. Every EC2 instance with an attached role exposes temporary credentials through the instance metadata service, and an attacker who can make requests from the host, including through a server-side request forgery flaw, can try to retrieve them. MITRE ATT&CK tracks this as Cloud Instance Metadata API (T1552.005).
Controls to apply as part of the AL2023 baseline:
- Require IMDSv2 (session tokens) on every launch template and enforce it across accounts. The full approach, including hop limits for containers and organisation-wide enforcement, is covered in the EC2 Instance Metadata Service Hardening Guide.
- Give each workload its own role with only the permissions it needs. A shared, broadly scoped role across many AL2023 hosts turns any single host compromise into account-wide access.
- Restrict which local processes can reach the metadata endpoint where possible, for example with host firewall rules that allow only the processes that need it.
- Alert on role credentials used from outside the instance's expected network, which is a common sign of stolen instance credentials.
Logging, file integrity and evidence
With the systemd journal replacing rsyslog by default, check that your log shipping agent reads from the journal or that you have installed and configured a forwarder deliberately. A baseline that assumes /var/log/messages will exist can leave a host with no off-box logs at all.
Minimum evidence for a hardened AL2023 host:
- SELinux AVC denials shipped centrally, with alerts on new denial patterns on enforcing hosts. A sudden burst of denials from a web service is often the first sign of exploitation.
- auditd rules for privileged command use, changes to
/etc/selinux/config,/etc/ssh/sshd_configand sudoers, and loading of kernel modules. - Package and kernel state: current kernel, live patch list and support window, repository version.
- Session Manager or SSH session logs tied to a named person or pipeline identity.
Store logs in an account the workload role cannot write to or delete from, so a compromised host cannot erase its own trail.
Migrating the last Amazon Linux 2 hosts
AWS's AL2 FAQ states that Amazon Linux 2 reached its end of support on 30 June 2026 and that customers should migrate to AL2023 now rather than waiting for a future version. Remaining AL2 hosts no longer receive security updates. Treat each one as a documented risk exception with an owner and a date, and isolate it as you would any unsupported system. The CentOS 7 End of Life guide describes the same containment pattern for another end-of-life distribution.
When migrating, rebuild rather than upgrade in place: launch a fresh AL2023 instance from a hardened image and move the workload. That gives you SELinux enforcing, the new update model and current packages from the start, instead of carrying years of configuration drift across.
Common failure patterns
- Permissive forever. SELinux is left in its default permissive mode because nobody owns the rollout. Logs fill with denials that nobody reads.
- Disabling SELinux to fix one application. A single failing service leads to SELinux being disabled on the whole image rather than the file context or port type being fixed.
- Live patching as a reason never to reboot. Hosts run past the three-month live patch window and stop receiving kernel fixes without anyone noticing.
- Stale images. Because AL2023 does not apply security updates at launch by default, instances launched from old images run months-old packages.
- Ported AL2 scripts. Hardening and compliance checks written for rsyslog, cron and YUM report results that do not reflect the real state of an AL2023 host.
- Re-enabling ssh-rsa. A legacy integration breaks and the old algorithm is switched back on everywhere.
- Over-privileged instance roles. The operating system is hardened, but the attached role can read every bucket in the account and IMDSv1 is still allowed.
Practitioner checklist
- Inventory every Amazon Linux 2 instance and assign an owner and a migration date or documented exception.
- Use a hardening benchmark written for AL2023, not one ported from AL2.
- Run workloads in permissive mode, review AVC denials with
ausearch, fix file contexts and port types, then set SELinux to enforcing through cloud-init in every launch template. - Report the percentage of instances in enforcing mode as a fleet metric.
- Enable kernel live patching through Systems Manager and set a reboot cadence shorter than the three-month live patch support window.
- Check that runtime security and observability agents that rely on eBPF still work with live patches applied.
- Build golden images on a schedule, pinned to a recorded repository version, scanned before release, with a maximum age.
- Keep ssh-rsa disabled; move interactive access to Session Manager or Instance Connect; remove long-lived keys from images.
- Require IMDSv2 and give each workload its own least-privilege role.
- Ship journal, audit and SELinux logs to an account the workload cannot modify.
Standards and references
- AWS: AL2023 security features
- AWS: SELinux for AL2023
- AWS: Change SELinux to enforcing mode on AL2023
- AWS: Kernel Live Patching on AL2023
- AWS: Comparing AL2 and AL2023
- AWS: Amazon Linux 2 FAQs
- CIS: CIS Benchmarks
- NIST: SP 800-53 Rev. 5 (CM-6 Configuration Settings, SI-2 Flaw Remediation, AC-3 Access Enforcement)
Related NHI Mgmt Group resources: Linux Server Hardening Guide · Amazon EC2 Security Guide · EC2 Instance Metadata Service Hardening Guide · AWS Systems Manager Security Guide