Lesson 11 of 12 · 12 min · Intermediate

Both platforms: secrets, TLS, disk encryption, backups, time and drift control

The controls that apply to every server: keep secrets out of files, automate TLS, encrypt disks, design backups that survive ransomware and test restores, keep time in sync, and use configuration management so your hardening does not drift.

In this lesson you will

  • Handle secrets so they are not exposed in files, repos or logs
  • Automate TLS certificates and verify the configuration
  • Design backups that survive ransomware and prove a restore
  • Prevent configuration drift with automation

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 600 and 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.

bash
# 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 works

On 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:

bash
nmap --script ssl-enum-ciphers -p 443 example.com
testssl.sh --fast example.com

For websites, add HSTS once everything works over HTTPS.

Encrypt disks

Disk encryption protects data if a disk, snapshot or backup is lost or stolen.

bash
lsblk -f                      # Ubuntu: is the data partition LUKS-encrypted?
sudo cryptsetup status NAME
powershell
Get-BitLockerVolume | Select-Object MountPoint,VolumeStatus,ProtectionStatus   # Windows

Escrow 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.

Backups: fragile vs ransomware-resilient

  • 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.
bash
# 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-test

On 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.

bash
timedatectl status           # Ubuntu: System clock synchronized: yes
chronyc tracking
powershell
w32tm /query /status         # Windows
w32tm /query /source

In 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.
yaml
- 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: reloaded

Run it on a schedule and treat unexpected differences as incidents worth investigating.

🧪 Lab

  1. Find one secret in your lab servers (a config or history entry), remove it, and store it properly.
  2. Test a TLS endpoint with nmap --script ssl-enum-ciphers and fix one weakness.
  3. Make a backup, then restore it to a different location and verify the data.
  4. Check time sync on both servers.
  5. Turn your SSH drop-in into an Ansible task and apply it.

Checkpoint

  1. Why must backup credentials be separate from normal admin credentials?
  2. What does the second "1" in 3-2-1-1-0 stand for?
  3. Why do clock errors matter for Kerberos and for investigations?
  4. What is configuration drift and how do you stop it?
  5. Name two places secrets should never be stored.