To secure an AlmaLinux VPS, create an admin user in the wheel group, log in with an SSH key, then put PermitRootLogin no and PasswordAuthentication no in a file called /etc/ssh/sshd_config.d/00-hardening.conf so it is read before AlmaLinux's own files. Finish with dnf-automatic (or a small cron script) so updates install every day and the server reboots only when dnf needs-restarting -r says it must.
Every command below was run on 21 November 2026 in fresh AlmaLinux 10.3 and AlmaLinux 9.9 test machines, and every output is what we got (the lab clock runs on UTC, so log lines read 20 Nov). It is written for a new Linux VPS at RS Computers in Amsterdam, Dublin or Prishtina, but works on any AlmaLinux server with root access. Running Debian or Ubuntu instead? Use our Debian 13 guide or the Ubuntu SSH keys and automatic updates guide.
Key facts
- AlmaLinux 10.3 still uses DNF 4 (
dnf-4.20.0in our lab), not DNF5. Fedora moved to DNF5 in Fedora 41, so Fedora guides fordnf5-automaticdo not apply. - The dnf-automatic config file is
/etc/dnf/automatic.confon both AlmaLinux 10 and 9, and the timer isdnf-automatic.timer, which runs daily at 06:00 plus a random delay of up to 60 minutes. - Out of the box, dnf-automatic only downloads updates:
apply_updates = noandreboot = never. - The default AlmaLinux SSH setting is
PermitRootLogin prohibit-password(root can still log in with a key) andPasswordAuthentication yes. - OpenSSH uses the first value it reads for each setting (sshd_config manual), and the files in
sshd_config.dare read in name order, so00-hardening.confbeats every other file there. - If root SSH login with a password was allowed during installation, the AlmaLinux installer writes
01-permitrootlogin.confwithPermitRootLogin yes(Anaconda source). A00-file overrides it. - The SSH service on AlmaLinux is called
sshd, and login attempts are logged in/var/log/secureand injournalctl -u sshd.
Quick version (you already have a key on the server for a wheel user)
- As root:
printf 'PermitRootLogin no\nPasswordAuthentication no\nKbdInteractiveAuthentication no\nPubkeyAuthentication yes\n' > /etc/ssh/sshd_config.d/00-hardening.conf- Check and apply:
sshd -t && systemctl reload sshd- Confirm:
sshd -T | grep -E "permitrootlogin|passwordauthentication|kbdinteractive"must printnothree times.- Test a new key login in a second terminal before closing the first one.
- Updates:
dnf install -y dnf-automatic, setapply_updates = yesandreboot = when-neededin/etc/dnf/automatic.conf, thensystemctl enable --now dnf-automatic.timer.
Why bots go after your SSH password
A server with a public IPv4 address gets login attempts almost at once. In a 30-day study with 10 cloud honeypots, Sophos recorded the first attack 52 seconds after one went live and an average of 13 attempts per minute per honeypot (Sophos, 2019). The bots try root, admin, test and lists of leaked passwords. Reusing passwords that leaked elsewhere is called credential stuffing (OWASP), and it works because people reuse passwords.
This is what three wrong password guesses look like in /var/log/secure on AlmaLinux 9 with the default settings:
Nov 20 23:03:57 lab-almasec9 sshd-session[826]: Failed password for root from 10.141.188.87 port 46818 ssh2
Nov 20 23:03:59 lab-almasec9 sshd-session[830]: Invalid user admin from 10.141.188.87 port 46826
Nov 20 23:04:01 lab-almasec9 sshd-session[830]: Failed password for invalid user admin from 10.141.188.87 port 46826 ssh2
Nov 20 23:04:02 lab-almasec9 sshd-session[832]: Invalid user test from 10.141.188.87 port 46830
Nov 20 23:04:04 lab-almasec9 sshd-session[832]: Failed password for invalid user test from 10.141.188.87 port 46830 ssh2
To count failed guesses and see which addresses send them, run these on your own server:
grep -c "Failed password" /var/log/secure
grep "Failed password" /var/log/secure | grep -oE "from [0-9a-f.:]+" | sort | uniq -c | sort -rn
lastb -n 5
journalctl -u sshd --no-pager | grep -c "Failed password"
3
3 from 10.141.188.87
test ssh:notty 10.141.188.87 Fri Nov 20 23:04 - 23:04 (00:00)
...
3
If /var/log/secure does not exist, the rsyslog package is not installed; the systemd journal still has everything, so use the journalctl line. A key stops this kind of attack because there is nothing to guess: an Ed25519 key is designed for about a 128-bit security level (RFC 8032), far beyond any password a bot can try at 13 attempts a minute.
Step 1: create a sudo user in the wheel group
Working as root all day means one typo can break the system and one stolen password gives everything. On AlmaLinux the admin group is wheel, not sudo. Its rule is already active in /etc/sudoers on both 10 and 9:
%wheel ALL=(ALL) ALL
Log in as root the first time, then create your user (we call it deploy; pick your own name) and give it a strong password, which sudo will ask for:
useradd -m -G wheel deploy
passwd deploy
id deploy
uid=1000(deploy) gid=1000(deploy) groups=1000(deploy),10(wheel)
Seeing 10(wheel) means the user can run sudo.
Step 2: make an SSH key on your PC and copy it
Run this on your own computer, not on the server. It works the same in Windows PowerShell, the macOS Terminal and Linux. Microsoft documents the Windows key steps here.
ssh-keygen -t ed25519 -C laptop
Press Enter to accept the default file and type a passphrase that protects the key if your PC is stolen. Our output (with an empty passphrase, lab only):
Generating public/private ed25519 key pair.
Your identification has been saved in /home/user/.ssh/id_ed25519
Your public key has been saved in /home/user/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:grCKkSz/kn//2Oxxv+3eJp0WxfUwPqweMk4NqEU6B8k laptop
The file ending in .pub is the public half that goes on the server. The file without an ending is your private key: never copy it anywhere. On macOS and Linux, copy the key with ssh-copy-id, which asks for the deploy password one last time:
ssh-copy-id deploy@YOUR_SERVER_IP
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/user/.ssh/id_ed25519.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Windows has no ssh-copy-id. In PowerShell, pipe the key into ssh instead; the part in quotes runs on the server and creates the folder and file with the right permissions:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@YOUR_SERVER_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
We ran the same server-side command from a Linux client against AlmaLinux 9, and the result was drwx------ for .ssh and -rw------- for authorized_keys, which is what sshd expects.
Now the important test. Keep your root session open and, in a second terminal, log in with the key only:
ssh -o PasswordAuthentication=no deploy@YOUR_SERVER_IP
sudo whoami
On AlmaLinux 10 the first sudo prints a short warning, then asks for the deploy password and answers root. If the key login fails, fix it now (wrong user, key not in ~/.ssh/authorized_keys, wrong permissions) and do not continue.
Step 3: disable root login and password authentication
From here on, work as deploy and become root with sudo -i. First look at what AlmaLinux already ships:
ls /etc/ssh/sshd_config.d/
sshd -T | grep -E "^(permitrootlogin|passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication) "
40-redhat-crypto-policies.conf
50-redhat.conf
permitrootlogin without-password
pubkeyauthentication yes
passwordauthentication yes
kbdinteractiveauthentication no
without-password is the old name of prohibit-password: root may log in with a key but not a password. Password login for every other user is on. 50-redhat.conf sets logging, PAM and X11 forwarding, not the login policy. If your server was installed from the ISO with root password login allowed, you will also see 01-permitrootlogin.conf. We created that file in the lab to copy the installer and it did what you would fear:
permitrootlogin yes
Editing /etc/ssh/sshd_config itself does not help, because its Include /etc/ssh/sshd_config.d/*.conf line comes first and the first value wins. So write your own file that sorts before all of them:
cat > /etc/ssh/sshd_config.d/00-hardening.conf <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
EOF
chmod 600 /etc/ssh/sshd_config.d/00-hardening.conf
sshd -t && systemctl reload sshd
sshd -T | grep -E "permitrootlogin|passwordauthentication|kbdinteractive"
permitrootlogin no
passwordauthentication no
kbdinteractiveauthentication no
sshd -t prints nothing when the config is valid; if it prints an error, nothing is reloaded and you fix the file first. Even with 01-permitrootlogin.conf still in place, root login is now no.
Prove it from your PC with a password attempt and a root attempt, then a normal key login:
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password deploy@YOUR_SERVER_IP
ssh root@YOUR_SERVER_IP
ssh deploy@YOUR_SERVER_IP
deploy@10.141.188.87: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@10.141.188.87: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
The word password is gone from the list of methods the server offers. The third command logs you in with the key. The server log shows the same story:
sshd-session[840]: Connection closed by authenticating user deploy 10.141.188.78 port 33254 [preauth]
sshd-session[842]: Connection closed by authenticating user root 10.141.188.78 port 33258 [preauth]
sshd-session[844]: Accepted publickey for deploy from 10.141.188.78 port 33266 ssh2: ED25519 SHA256:grCKkSz/kn//2Oxxv+3eJp0WxfUwPqweMk4NqEU6B8k
Locked out anyway? Open the console in the client area, log in as root with its password (the console is not SSH), and move 00-hardening.conf out of the folder.
Step 4: automatic daily updates with dnf-automatic
This is the native AlmaLinux way. Install it and keep a copy of the original config:
dnf install -y dnf-automatic
cp -a /etc/dnf/automatic.conf /etc/dnf/automatic.conf.orig
sed -i -e "s/^apply_updates = no/apply_updates = yes/" -e "s/^reboot = never/reboot = when-needed/" /etc/dnf/automatic.conf
grep -E "^(upgrade_type|apply_updates|reboot|emit_via) " /etc/dnf/automatic.conf
upgrade_type = default
apply_updates = yes
reboot = when-needed
emit_via = stdio
upgrade_type = default installs all updates; change it to security to install only updates that have a security advisory. reboot = when-needed reboots only when a change needs it, such as a kernel or systemd update, and the default reboot_command waits 5 minutes. when-changed would reboot after any update (dnf-automatic documentation). Then start the timer:
systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timer --no-pager
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sat 2026-11-21 06:17:21 UTC 7h - - dnf-automatic.timer dnf-automatic.service
Use dnf-automatic.timer, not dnf-automatic-install.timer or the others: those ignore your config file. To test it right away, start the service by hand and read its log. On our AlmaLinux 10 test it installed 7 pending packages:
systemctl start dnf-automatic.service
journalctl -u dnf-automatic.service --no-pager | tail -n 12
dnf-automatic[1566]: The following updates have been applied on 'lab-almasec':
dnf-automatic[1566]: Upgrading:
dnf-automatic[1566]: curl x86_64 8.12.1-9.el10_3 baseos 218 k
...
dnf-automatic[1566]: krb5-libs x86_64 1.21.3-11.el10_3.2 baseos 764 k
dnf-automatic[1566]: Upgrade 7 Packages
dnf-automatic[1566]: Updates completed at Fri 20 Nov 2026 11:04:53 PM UTC
systemd[1]: Finished dnf-automatic.service - dnf automatic.
To pick your own time, say 03:30, add a timer override. The empty OnCalendar= line clears the 06:00 default:
mkdir -p /etc/systemd/system/dnf-automatic.timer.d
printf '[Timer]\nOnCalendar=\nOnCalendar=*-*-* 03:30\nRandomizedDelaySec=15m\n' > /etc/systemd/system/dnf-automatic.timer.d/override.conf
systemctl daemon-reload
systemctl restart dnf-automatic.timer
The next run then showed Sat 2026-11-21 03:38:09 UTC, inside the 15-minute window.
Step 5: the cron way, update + upgrade daily and reboot only when needed
Prefer one plain script with its own log file? Pick this or dnf-automatic, not both; we disabled the timer first with systemctl disable --now dnf-automatic.timer. The reboot check needs dnf needs-restarting, which is in dnf-plugins-core. Our minimal test image did not have it:
No such command: needs-restarting. Please use /usr/bin/dnf --help
dnf install -y dnf-plugins-core
dnf needs-restarting -r; echo "exit code $?"
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.
exit code 0
Exit code 1 means a reboot is required, 0 means it is not (needs-restarting docs). Create the script:
cat > /usr/local/sbin/auto-update.sh <<'EOF'
#!/bin/bash
# Daily update + upgrade, log to a file, reboot only when dnf says it is needed.
LOG=/var/log/auto-update.log
exec >>"$LOG" 2>&1
echo "=== $(date '+%F %T') start"
dnf -y upgrade --refresh
rc=$?
echo "dnf exit code: $rc"
if [ "$rc" -eq 0 ]; then
dnf needs-restarting -r
if [ $? -eq 1 ]; then
echo "reboot needed, rebooting in 2 minutes"
/usr/sbin/shutdown -r +2 "auto-update: reboot after updates"
fi
fi
echo "=== $(date '+%F %T') end"
EOF
chmod 700 /usr/local/sbin/auto-update.sh
bash -n /usr/local/sbin/auto-update.sh && echo syntax-ok
If dnf fails, the script does not reboot, and the error is in the log. Schedule it every night at 03:30 with a system cron file (cronie was installed and running on our AlmaLinux 10 image):
echo "30 3 * * * root /usr/local/sbin/auto-update.sh" > /etc/cron.d/auto-update
chmod 644 /etc/cron.d/auto-update
Test it by running the script once by hand and reading the log. On AlmaLinux 9, where a systemd update was waiting, it upgraded 10 packages and scheduled the reboot:
/usr/local/sbin/auto-update.sh
tail -n 20 /var/log/auto-update.log
Complete!
dnf exit code: 0
Core libraries or services have been updated since boot-up:
* systemd
Reboot is required to fully utilize these updates.
More information: https://access.redhat.com/solutions/27943
reboot needed, rebooting in 2 minutes
Reboot scheduled for Fri 2026-11-20 23:07:27 UTC, use 'shutdown -c' to cancel.
=== 2026-11-20 23:05:27 end
After the reboot, dnf needs-restarting -r returned 0 again. On AlmaLinux 10, with nothing left to install, the log ended with Nothing to do. and Reboot should not be necessary. To prove cron really runs it, we set the cron line two minutes ahead and checked /var/log/cron:
CROND[1942]: (root) CMD (/usr/local/sbin/auto-update.sh)
CROND[1941]: (root) CMDEND (/usr/local/sbin/auto-update.sh)
Stop the log from growing forever with a logrotate file; logrotate -d /etc/logrotate.d/auto-update checks it without changing anything:
printf '/var/log/auto-update.log {\n monthly\n rotate 6\n compress\n missingok\n notifempty\n}\n' > /etc/logrotate.d/auto-update
Be honest with yourself about the risk. A blind full upgrade can bring a new PHP, database or kernel version that your application does not like, and a reboot at 03:30 takes the site down for a minute. If an app needs a fixed version, exclude its packages in dnf's configuration or switch to upgrade_type = security. Keep backups you can restore: every RS Computers server has free weekly backups (the last two are kept) that you restore with one click, and our VPS backup and restore guide shows how. Kernel fixes such as the one in our NoisyTCP kernel check only take effect after that reboot.
AlmaLinux 10 vs AlmaLinux 9: what differs
| Item | AlmaLinux 10.3 | AlmaLinux 9.9 |
|---|---|---|
| DNF version | dnf 4.20.0 (not DNF5) | dnf 4.14.0 |
| OpenSSH | 9.9p1 | 9.9p1 |
| Files in sshd_config.d | 40-redhat-crypto-policies.conf, 50-redhat.conf | 50-redhat.conf only (crypto policy include is inside it) |
| Default root / password login | prohibit-password / yes | prohibit-password / yes |
| dnf-automatic config | /etc/dnf/automatic.conf, adds systemd_inhibit = yes (blocks shutdown during updates) | /etc/dnf/automatic.conf, no systemd_inhibit line |
| Timers | dnf-automatic, -install, -download, -notifyonly | the same four |
| Admin group | wheel | wheel |
| firewalld version | 2.4.3 | 1.3.4 |
Every command in this guide worked unchanged on both. On Rocky Linux 10.3 we found the same two sshd_config.d files, the same dnf 4.20.0 and the same dnf-automatic defaults, so Rocky readers can follow the same steps.
Bonus: firewalld and fail2ban
Allow SSH before you tighten anything else. In our test the default public zone already allowed ssh, plus cockpit and dhcpv6-client:
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --remove-service=cockpit
firewall-cmd --reload
firewall-cmd --list-services
Warning: ALREADY_ENABLED: ssh
success
success
success
dhcpv6-client ssh
Remove cockpit only if you do not use the Cockpit web console. Other services are opened the same way (firewall-cmd manual). We opened a fresh SSH session after the reload and it worked.
With password login off, fail2ban is optional; it mainly cuts log noise. It comes from EPEL. On AlmaLinux 10:
dnf install -y epel-release
dnf install -y fail2ban-server fail2ban-firewalld
printf '[sshd]\nenabled = true\nbackend = systemd\nmaxretry = 5\nfindtime = 10m\nbantime = 1h\n' > /etc/fail2ban/jail.d/sshd.local
systemctl enable --now fail2ban
fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd + _COMM=sshd-session
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
fail2ban-firewalld makes bans go through firewalld. One limit of our lab: it ran in containers with SELinux disabled, so SELinux behaviour was not part of the test. On a normal AlmaLinux VPS SELinux is enforcing; none of the steps above change SELinux settings.
Checklist
| Step | Command to verify | Good result |
|---|---|---|
| Admin user | id deploy | 10(wheel) in the list |
| Key login | ssh -o PasswordAuthentication=no deploy@IP | Logs in without a password prompt |
| Root and passwords off | sshd -T | grep -E "permitrootlogin|passwordauthentication|kbdinteractive" | Three lines ending in no |
| Password attempt refused | ssh -o PubkeyAuthentication=no deploy@IP | Permission denied (publickey,...) |
| Updates scheduled | systemctl list-timers dnf-automatic.timer or cat /etc/cron.d/auto-update | A NEXT time, or the cron line |
| Reboot check works | dnf needs-restarting -r | A clear answer, exit code 0 or 1 |
| Firewall | firewall-cmd --list-services | ssh is listed |
| Backups | Client area backup list | A recent backup you know how to restore |
Frequently asked questions
How do I disable root login on AlmaLinux?
Create /etc/ssh/sshd_config.d/00-hardening.conf with PermitRootLogin no, run sshd -t && systemctl reload sshd, and check with sshd -T | grep permitrootlogin. The 00- name matters: OpenSSH keeps the first value it reads, so this file beats 01-permitrootlogin.conf and 50-redhat.conf. Make sure a wheel user can log in with a key first.
Why does my change in /etc/ssh/sshd_config have no effect?
Because sshd_config includes sshd_config.d/*.conf near the top, and the first value read for each setting wins. A 01-permitrootlogin.conf written by the installer, or any other file there, overrides what you write lower down in the main file. Put your settings in a drop-in file that sorts first.
Does AlmaLinux 10 use dnf5 for dnf-automatic?
No. AlmaLinux 10.3 ships dnf 4.20.0, the package is still called dnf-automatic, the config is /etc/dnf/automatic.conf and the timer is dnf-automatic.timer, the same as on AlmaLinux 9. DNF5 is a Fedora change since Fedora 41.
Should I install all updates or only security updates?
All updates (upgrade_type = default) keep the system fully current, which suits most single-purpose VPS. Security only (upgrade_type = security) changes less, which suits servers with an application that is sensitive to package versions. Either way, keep a restorable backup.
Will dnf-automatic reboot my server?
Not by default: reboot = never. Set reboot = when-needed and it reboots only after updates such as the kernel or systemd, 5 minutes after the update with the default reboot_command. In the cron script, dnf needs-restarting -r makes the same decision.
Where are SSH login attempts logged on AlmaLinux?
In /var/log/secure when rsyslog is installed, and always in the journal: journalctl -u sshd. lastb lists failed logins from /var/log/btmp. Debian and Ubuntu use /var/log/auth.log instead.
Need a hand?
If you are starting fresh, a VPS or VDS with NVMe in Amsterdam, Dublin or Prishtina can be ordered with AlmaLinux or Rocky Linux, full root access and free weekly backups, so you can follow this guide in minutes and roll back if an update goes wrong. VPS plans use shared vCPUs; if your workload needs dedicated cores, look at the dedicated vCPU VDS plans.
Want this hardening, the update script or a full server setup done for you? We build custom setups and systems quoted per job. Write to us on Telegram or by email at info@rscomputers-ks.com.