Initial Server Setup on AlmaLinux 9, Rocky Linux 9 and CentOS Stream 9
A first-day checklist for AlmaLinux 9, Rocky Linux 9 and CentOS Stream 9: updates, a sudo user with SSH keys, firewalld, hostname, time zone and automatic updates.
This checklist takes a freshly installed AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9 server from "root password in an email" to a sane baseline: patched, reachable only through a personal sudo account with an SSH key, firewalled, correctly named and timed, and installing security updates on its own. Each step is short on purpose; it covers what a new server needs on day one, not every option of every tool.
CentOS 7 reached end of life on 30 June 2024 and CentOS Linux 8 at the end of 2021; neither receives security fixes. AlmaLinux and Rocky Linux are the community rebuilds of RHEL that replace them, and CentOS Stream is the rolling preview of the next RHEL minor release. All three use the same commands below.
Requirements
- A new server running AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9.
- The
rootpassword or root SSH access from your provider. The examples use the address203.0.113.10and create a user calleddeploy. - Access to your provider's web console, in case you lock yourself out of SSH.
Step 1: Log in and install updates
Connect as root from your own computer:
ssh root@203.0.113.10Install images are often months old, so update every package before doing anything else:
dnf -y upgradeIf the transaction installed a new kernel, reboot so the server actually runs it, then log in again:
rebootStep 2: Create a non-root sudo user
Working as root all the time means every typo runs with full privileges and every action is logged under the same name. Create a personal account and set its password:
adduser deploy
passwd deployMembers of the wheel group may run any command through sudo on the RHEL family. Add the new user to it:
usermod -aG wheel deployStep 3: Set up SSH key login
On your local computer, create a key pair if you do not have one yet, and copy the public key to the new account:
ssh-keygen -t ed25519
ssh-copy-id deploy@203.0.113.10Open a second terminal and confirm that key login and sudo both work before you change anything else:
ssh deploy@203.0.113.10
sudo whoamiThe second command must print root. Only then turn off root logins and password logins. On the 9 releases, /etc/ssh/sshd_config includes every file in /etc/ssh/sshd_config.d/ and the first value found for an option wins, so a file with a low number overrides the defaults shipped by the distribution or by cloud-init:
sudo tee /etc/ssh/sshd_config.d/00-baseline.conf > /dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
EOFCheck the syntax, reload the daemon and confirm the values that are really in effect:
sudo sshd -t
sudo systemctl reload sshd
sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication)'Keep your existing session open and test a fresh login from another terminal. If it fails, you still have a shell to undo the change.
Step 4: Enable the firewall
firewalld is the standard firewall on these systems. Minimal and cloud images do not always include it, so install it, start it and enable it at boot:
sudo dnf -y install firewalld
sudo systemctl enable --now firewalldThe default public zone already allows SSH, so your session survives. Look at what is open:
sudo firewall-cmd --list-allOpen further services only when something is actually listening. For a web server, for example:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadRules added with --permanent are written to disk and take effect at the next reload; rules added without it apply immediately and vanish on reload or reboot.
Step 5: Set the hostname and time zone
Give the server a name that tells you what it is when you have five terminals open:
sudo hostnamectl set-hostname web1.example.comFind your time zone and set it. Log timestamps and cron schedules follow this setting:
timedatectl list-timezones | grep -i europe
sudo timedatectl set-timezone Europe/BerlinTime synchronisation is handled by chronyd. Make sure it is running, then check the result:
sudo dnf -y install chrony
sudo systemctl enable --now chronyd
timedatectlThe output should show your zone and System clock synchronized: yes.
Step 6: Turn on automatic updates
dnf-automatic runs dnf from a systemd timer. Install it:
sudo dnf -y install dnf-automaticOpen /etc/dnf/automatic.conf and set these two options in the [commands] section:
upgrade_type = security
apply_updates = yesupgrade_type = security restricts the run to packages that have a security advisory; default installs every available update. apply_updates = yes installs what was downloaded instead of only reporting it. Enable the timer, not the service:
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timerBy default the tool never reboots (reboot = never in the same file), so a new kernel is only used after you restart the server yourself. Plan a reboot window, or set reboot = when-needed if unattended reboots are acceptable for this machine.
Step 7: Verify the baseline
Run these as your sudo user. Together they confirm each step above:
sudo dnf check-update
id deploy
sudo firewall-cmd --state
hostnamectl --static
timedatectl | grep -E 'Time zone|synchronized'
systemctl is-enabled dnf-automatic.timer
getenforcegetenforce should print Enforcing. SELinux is enabled out of the box and should stay that way; when it blocks something, the fix is a label or a boolean, not turning it off.
Frequently asked questions
Which should I pick: AlmaLinux, Rocky Linux or CentOS Stream?
AlmaLinux and Rocky Linux follow RHEL point releases and behave like the CentOS you knew. CentOS Stream sits slightly ahead of RHEL and has no point releases, so packages change continuously. For a production server that should stay predictable, choose one of the two rebuilds.
Can I upgrade a CentOS 7 server in place instead of starting fresh?
Conversion and upgrade tools exist, but a multi-version jump on a machine you depend on is risky. For a typical VPS it is faster and safer to create a new server on a 9 release, run this checklist, and move the data and configuration across.
I disabled password login and lost my key. How do I get back in?
Use your provider's web console, which is not affected by SSH settings, and log in there with the password of your sudo user. Then add a new public key to ~/.ssh/authorized_keys or remove /etc/ssh/sshd_config.d/00-baseline.conf and reload sshd.
Should I also change the SSH port?
It cuts down the noise in your logs but adds no real protection once password logins are off. If you do change it, the new port has to be allowed in firewalld and labelled for SELinux before you reload sshd, otherwise the daemon cannot bind to it.