Some controls do not belong to Ubuntu or Windows; they belong to every server you run. This lesson covers the five that most often decide whether a bad day is an inconvenience or a catastrophe.
Secrets: keep them out of the obvious places
Hard-coded credentials in code, .env files in web roots, passwords in shell history and tokens in CI logs are how many breaches escalate.
- Never commit secrets to a repository. Scan for them (
gitleaks,trufflehog) and rotate anything that ever leaked. - Use a secrets manager (HashiCorp Vault, your cloud's secrets service, Azure Key Vault) or encrypt files with SOPS or age. On Windows prefer gMSA and DPAPI-backed stores over files.
- Restrict file permissions: on Ubuntu,
chmod 600and the right owner for any file with a credential; on Windows, remove broad ACL entries (icacls). - Rotate on a schedule and immediately after a suspected exposure or staff change.
- Check history and logs:
grep -i password ~/.bash_history, and make sure applications do not log secrets.
TLS: automate it, then test it
Expired or weak certificates cause outages and downgrade attacks. Automate issuance and renewal.
# Ubuntu: Let's Encrypt via certbot
sudo snap install certbot --classic
sudo certbot --nginx -d example.com
sudo certbot renew --dry-run # confirm automatic renewal worksOn Windows, use an ACME client such as win-acme or Posh-ACME, or your internal PKI with auto-enrolment.
Prefer TLS 1.2 and 1.3, disable the rest, and test from outside:
nmap --script ssl-enum-ciphers -p 443 example.com
testssl.sh --fast example.comFor websites, add HSTS once everything works over HTTPS.
Encrypt disks
Disk encryption protects data if a disk, snapshot or backup is lost or stolen.
lsblk -f # Ubuntu: is the data partition LUKS-encrypted?
sudo cryptsetup status NAMEGet-BitLockerVolume | Select-Object MountPoint,VolumeStatus,ProtectionStatus # WindowsEscrow Windows BitLocker recovery keys in Active Directory or Entra ID, and store LUKS recovery material in your vault. An encrypted disk with a lost key is a data-loss event.
Backups that survive ransomware
Ransomware crews hunt for backups and delete them first. Design for that.
- 3-2-1-1-0: three copies, two media types, one off-site, one offline or immutable, and zero restore errors in your tests.
- Separate credentials. The account that writes backups must not be the one that can delete them, and must not be a domain admin.
- Immutability: object-lock or write-once storage, or an air-gapped copy.
- Test restores on a schedule. An untested backup is a hope, not a control.
# Ubuntu example with restic (encrypted, deduplicated)
restic -r sftp:backup@backuphost:/srv/restic init
restic -r sftp:backup@backuphost:/srv/restic backup /etc /var/lib/myapp
restic -r sftp:backup@backuphost:/srv/restic check
restic -r sftp:backup@backuphost:/srv/restic restore latest --target /tmp/restore-testOn Windows use Windows Server Backup (VSS-aware) or your enterprise backup product, to a target the server itself cannot overwrite. Alert on shadow-copy deletion (lesson 10).
Time must be right
Logs, Kerberos, certificates and incident timelines all depend on accurate time.
timedatectl status # Ubuntu: System clock synchronized: yes
chronyc trackingw32tm /query /status # Windows
w32tm /query /sourceIn a domain, members follow the domain hierarchy; make sure the PDC emulator syncs to a reliable source. Kerberos fails when clocks drift more than a few minutes.
Stop drift: make hardening repeatable
A server hardened by hand is drifting the day after. Put the settings in code and re-apply them.
- Ubuntu: Ansible (the ansible-lockdown project publishes CIS roles for Ubuntu and Windows), or cloud-init for first boot.
- Windows: Group Policy, Intune, or PowerShell DSC, with Microsoft security baselines imported as the starting point.
- Golden images: build hardened images (Packer) so new servers start hardened.
- name: Harden sshd
hosts: ubuntu_servers
become: true
tasks:
- name: Drop-in hardening file
ansible.builtin.copy:
dest: /etc/ssh/sshd_config.d/00-hardening.conf
mode: "0644"
content: |
PermitRootLogin no
PasswordAuthentication no
AuthenticationMethods publickey
notify: Reload ssh
handlers:
- name: Reload ssh
ansible.builtin.service:
name: ssh
state: reloadedRun it on a schedule and treat unexpected differences as incidents worth investigating.
🧪 Lab
- Find one secret in your lab servers (a config or history entry), remove it, and store it properly.
- Test a TLS endpoint with
nmap --script ssl-enum-ciphersand fix one weakness. - Make a backup, then restore it to a different location and verify the data.
- Check time sync on both servers.
- Turn your SSH drop-in into an Ansible task and apply it.
Checkpoint
- Why must backup credentials be separate from normal admin credentials?
- What does the second "1" in 3-2-1-1-0 stand for?
- Why do clock errors matter for Kerberos and for investigations?
- What is configuration drift and how do you stop it?
- Name two places secrets should never be stored.