guest@websec ~ % man s01-ubuntu-server-setup
Ubuntu Server Setup
Turn a fresh Ubuntu 24.04 server into a safe one: key login, no root, a firewall, Docker, Node, Ruby and Python. Pick a topic below, or press ▶ play to run them all.
Patch packages first, create a non-root
sudo user with your Ed25519 SSH key, test login in a second terminal tab before disabling root & password SSH, allow OpenSSH before enabling ufw, and bind Docker databases to 127.0.0.1 so they don't bypass your firewall.
my server came with:
⚙ use my own values in the commands
Commands
If you lock yourself out
Open your provider's web console (it works without SSH), log in with the user's password, then undo:
sudo ufw disable, or sudo rm /etc/ssh/sshd_config.d/00-hardening.conf && sudo systemctl restart ssh.Cheat sheet
| step | command |
|---|---|
| connect | ssh -i key.pem user@IP (key must be chmod 600) |
| update | sudo apt update && sudo apt upgrade -y |
| new sudo user | adduser ubuntu && usermod -aG sudo ubuntu |
| switch user | su - ubuntu · back to root: exit · root shell: sudo -i |
| add a key | ~/.ssh = 700, ~/.ssh/authorized_keys = 600, one key per line, append with >> |
| harden sshd | /etc/ssh/sshd_config.d/00-hardening.conf → sudo sshd -t → sudo systemctl restart ssh |
| no sudo password | /etc/sudoers.d/90-ubuntu with ubuntu ALL=(ALL) NOPASSWD:ALL, then sudo visudo -c |
| firewall | sudo ufw allow OpenSSH first, then 80/tcp, 443/tcp, sudo ufw enable |
| firewall rules | ufw status numbered · ufw delete N · ufw allow from IP to any port P proto tcp |
| docker | curl -fsSL https://get.docker.com | sudo sh · sudo usermod -aG docker $USER · publish as -p 127.0.0.1:P:P |
| node | nvm install --lts · nvm use 22 · nvm alias default 22 |
| ruby | rvm install 3.4 · rvm use 3.4 --default · rvm list |
| python | pyenv install 3.13 · pyenv global 3.13 · pyenv local 3.12 (per folder) |