ARTICLE - CDN, Security & Monitoring

New Server Hardening Checklist

Effective hardening means retaining a recovery route and checking live settings, listening services and external access, rather than counting configuration lines that may not apply.

2026-08-12 16IDC Original 76 views
Advertisement

Before putting a new server online, make sure you can recover access if remote login fails. Then update software and restrict SSH and network access. A line in a configuration file does not prove a rule is effective: check live service settings, local listeners and external reachability separately, and test a backup restore.

The commands target an Ubuntu server using systemd, OpenSSH and UFW, with an existing administrator account that can use sudo. Cloud images, other distributions, containers and established applications can have different service names or rules. Record existing settings and schedule a maintenance window before changes.

Preserve a Recovery Route Before Changes

Confirm cloud console or out-of-band access works, retain a restorable backup and keep the current SSH session open. Prepare a second terminal for login tests; both the cloud security group and host firewall must allow the management source to reach the current SSH port. Do not change the port, authentication and firewall together before testing.

The figure distinguishes configuration checks from actual access: valid syntax does not prove that the intended account can log in.

SSH Change Verification Steps Keep old session Check settings Test new login Close old session Check effective values Revert if login fails Confirm console recovery access separately
Figure 1: SSH Change Verification Steps (Source: preserve recovery access, then verify settings and a new connection)

Update the System and Check Accounts

Inspect pending packages and update during a maintenance window; a kernel or critical service update may require a reboot. Confirm backups and application compatibility first:

sudo apt update
sudo apt upgrade

Confirm the commands finish without unresolved package-manager errors, then check whether a reboot is required and whether the application is healthy. Use the Ubuntu automatic updates documentation to inspect the actual unattended-upgrades sources and reboot policy; do not assume all images use the same defaults.

Give each administrator a separate account and confirm login and necessary sudo access. Disable accounts no longer in use and run services under separate, minimally privileged identities where possible. Edit sudo rules with sudo visudo to avoid breaking authorization. See Server Initial Security for account setup.

Configure and Verify SSH

First generate a key on the client and install its public key into the target account's ~/.ssh/authorized_keys over a trusted channel. From a second terminal, confirm that the non-root account can log in with the key and use sudo. Keep the private key protected on the client; do not paste it onto the server. If password, keyboard-interactive or other authentication is required, arrange an alternative first.

Back up the original configuration and inspect /etc/ssh/sshd_config and included files in an editor. Set the following in the applicable global configuration; these are configuration directives, not shell commands:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no

The Ubuntu OpenSSH documentation describes how configuration snippets are read. For most options the first obtained value is used, so a new snippet might not override an existing setting. Match conditions can also change the effective configuration for a particular connection.

sudo sshd -t
sudo sshd -T | grep -E '^(permitrootlogin|passwordauthentication|kbdinteractiveauthentication) '

The first command should exit successfully without output; the second should show no for all three options. If Match rules exist, use sshd -T -C with the actual user, source address and host. If values differ, inspect include order and conditions before continuing.

sudo systemctl reload ssh.service

After the command succeeds, use a second terminal to log in again with that account's key and confirm sudo works. Test that password authentication is rejected from the same source before closing the original session. On failure, restore the saved configuration through the old session or console, then check syntax and reload again. See the SSH Hardening Guide for more on keys and authentication.

Restrict the Firewall and Verify Externally

Inventory actual service ports and management sources first. This example assumes SSH still uses TCP 22, web ports need public access and UFW is installed. If SSH uses a different port, replace 22 first and allow it in the cloud security group too. Open 80 and 443 only on hosts that need web access; do not expose databases and management interfaces by default.

sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw default deny incoming
sudo ufw enable
sudo ufw status verbose

The final command should show UFW as active, incoming traffic denied by default and the required ports allowed. Inspect existing rules and remove unnecessary broad ones. The example allows SSH from any source; if a fixed management address is available, use a source-restricted rule and test a new connection before replacing the old rule. If IPv6 is enabled, inspect its rules too. With Docker or similar components, check their firewall behavior separately. See the Ubuntu firewall documentation.

sudo ss -tulpen

The output lists TCP and UDP listening ports and addresses. Compare it with the service inventory and investigate unknown listeners; 0.0.0.0 and [::] can indicate listening on all interfaces. From an authorized external network, test the required ports over IPv4 and IPv6 separately. Scanning common ports does not establish that every port is closed, and dropped packets alone do not identify the cause. If access fails, check the application listener, host firewall and cloud security group in turn. See Linux Firewall Configuration.

Logs, Backups and Acceptance

Confirm system and SSH login logs are written, have sufficient space and rotate under policy. Copy important logs to a separate location and restrict access. Back up databases, configuration and uploads using application-consistent methods; keep copies in a separate account or storage location and restrict deletion. Set frequency from the acceptable data-loss and recovery objectives, then restore in an isolated environment and check both data and the application rather than trusting job success alone.

Check Acceptable result
Updates No unresolved update errors; required reboot scheduled and services checked
SSH Effective settings match the plan; new key login and sudo both work
Network Known listeners match the inventory; authorized external access matches policy
Logs Test login events are present; rotation and a separate copy are configured
Recovery Data restored and verified in isolation; time and issues recorded

Limitations

This is an introductory baseline for one Ubuntu host, not proof of compliance or a complete treatment of application flaws, supply-chain risks or incident forensics. Multiple interfaces, jump hosts, automation accounts and two-factor authentication can require different SSH or network rules; identify dependencies before changing them. Official documents were checked on 2026-11-28.

FAQ

What if SSH login fails after the change?

Keep the old session or enter the cloud console. Check sshd -t, effective configuration and journalctl -u ssh.service, then inspect the client key, account permissions and both host and cloud firewall rules. Restore the previous configuration and verify a new connection before changing one item at a time.

Can a different SSH port replace key authentication?

No. Changing the port may reduce automated noise aimed at the default port, but it does not replace authentication or source restrictions. If a port change is needed, allow the new port in both firewall layers, test a new connection, then remove the old rule while retaining console recovery access.

Does a successful snapshot prove the backup can be restored?

No. A successful snapshot or backup job only confirms its creation process; it does not guarantee database consistency, working credentials or application startup. Restore regularly in an isolated environment and validate important data, backup account isolation and deletion permissions.

Related Providers

  • Wazuh: consider it for centralized host event and file integrity collection.
  • Cloudflare WAF: consider edge rules for a public web application, not as a replacement for host hardening.

Community & Resources

Original source: 16IDC Original ↗