Every time I spin up a new Ubuntu server I go through the same handful of steps before anything else touches it. This post is that checklist, written down so I (and hopefully you) don’t have to piece it together again. It assumes a fresh Ubuntu 24.04 LTS install where your SSH public key is already in place for the initial login.
Throughout the post I use youruser as the new account name and 2222 as the new SSH port. Replace both with your own values.
Golden rule: keep your current SSH session open the whole time and test every change from a second terminal. That way a typo never locks you out.