Home AlmalinuxAlmaLinux 9 Initial Server Setup and Hardening Guide

AlmaLinux 9 Initial Server Setup and Hardening Guide

by Knowledge Base Linux
AlmaLinux 9 Initial Server Setup and — AlmaLinux 9 Initial Server Setup and Hardening Guide

A fresh AlmaLinux installation is functional, but it is not yet ready for the public internet. A proper AlmaLinux initial server setup means updating the system, creating a non-root administrator, locking down SSH, enabling the firewall and removing anything you do not need. In this guide we go through the essential first-hour checklist that turns a default install into a hardened server you can trust in production. This article covers AlmaLinux 9 Initial Server Setup and in detail.

Step 1: Update the System – AlmaLinux 9 Initial Server Setup and

Log in as root (or with your install-time admin user) and apply all updates first, so every later step works with patched software:

sudo dnf update -y
sudo reboot

Then confirm the release with cat /etc/os-release.

Step 2: Set the Hostname and Timezone – AlmaLinux 9 Initial Server Setup and

A clear hostname makes log analysis and multi-server management far easier:

sudo hostnamectl set-hostname server1.example.com
sudo timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl

Correct time matters for logs, TLS certificates and cron jobs. If you manage several machines, our article on how to change the hostname in Linux covers the details for other distributions too.

Step 3: Create a Sudo User in Your AlmaLinux Initial Server Setup

Working as root all day is risky: one typo can destroy the system, and attackers constantly scan for root logins. Create your daily admin account:

sudo adduser admin
sudo passwd admin
sudo usermod -aG wheel admin

Members of the wheel group can run privileged commands with sudo. Test the new account in a second SSH session before you close the root session.

AlmaLinux initial server setup security configuration workspace

Step 4: Secure SSH Access

Generate a key pair on your workstation (see our guide on generating SSH keys on Linux), copy the public key to the server, then harden the daemon. Edit /etc/ssh/sshd_config.d/99-hardening.conf:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3

Reload SSH and verify you can still log in as the sudo user with your key before logging out anywhere:

sudo systemctl reload sshd

Step 5: Enable the Firewall

AlmaLinux ships with firewalld. Enable it and allow only the services you actually run:

sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

Every closed port is one less attack vector. Add services deliberately, not “just in case”.

Step 6: Add Brute-Force Protection and Housekeeping

Install Fail2ban to block repeated login attempts automatically:

sudo dnf install -y epel-release
sudo dnf install -y fail2ban
sudo systemctl enable --now fail2ban

Our tutorial on installing Fail2Ban to protect SSH explains jail configuration in depth. Also check disk and memory headroom (df -h, free -h) and consider adding swap on small VPS instances so the kernel does not kill your applications under pressure.

Step 7: Keep SELinux Enforcing

Unlike older advice, do not disable SELinux. Confirm it is enforcing with getenforce. It should return Enforcing. SELinux adds a strong mandatory access-control layer that limits the damage if a service is compromised, and modern AlmaLinux tooling makes it manageable.

Troubleshooting

Locked out after SSH changes: use your provider’s web console to log in and fix the sshd drop-in file — this is why you test in a second session first. Firewall blocks a needed service: list the active zone with firewall-cmd --get-active-zones and add the service to the correct zone. sudo user cannot escalate: verify group membership with id admin and that the %wheel line in /etc/sudoers is enabled (edit only with visudo).

Step 8: Disable Unused Services and Add a Login Banner

Every listening service is a potential entry point. List what is exposed and remove what you do not use:

sudo ss -tulpn
sudo systemctl disable --now cups bluetooth avahi-daemon 2>/dev/null

On a typical web or database server you need little beyond SSH, your application and the system basics. Fewer services also mean fewer patches and fewer surprises. While you are editing the login experience, add a short legal banner in /etc/ssh/banner and point sshd to it with a Banner /etc/ssh/banner line — a small step that strengthens your position if a system is ever investigated.

Step 9: Turn On Auditing and Review Logs Weekly

AlmaLinux includes the audit framework, which records security-relevant events such as privilege escalation and file changes in protected directories. Make sure it is running:

sudo systemctl enable --now auditd
sudo auditctl -l

Pair it with a weekly habit: skim sudo journalctl -p warning --since "1 week ago" and the authentication log for failed logins. Ten minutes of review catches misconfigurations and probing early, long before they become incidents. Together with the update routine from the DNF Automatic guide on this site, auditing completes a basic but genuinely effective operations loop for a small server.

Conclusion

A careful AlmaLinux initial server setup — updates, hostname and timezone, a sudo user, key-only SSH, firewalld, Fail2ban and SELinux left enforcing — closes the vast majority of automated attacks that scan new servers within minutes of going online. Make this checklist part of every deployment and your AlmaLinux machines will start life secure.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.