guest@websec: ~/websec/s01-ubuntu-server-setup — zsh — 100×40 by SaKKo YouTube ENTH
ssh

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

    stepcommand
    connectssh -i key.pem user@IP (key must be chmod 600)
    updatesudo apt update && sudo apt upgrade -y
    new sudo useradduser ubuntu && usermod -aG sudo ubuntu
    switch usersu - 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
    firewallsudo ufw allow OpenSSH first, then 80/tcp, 443/tcp, sudo ufw enable
    firewall rulesufw status numbered · ufw delete N · ufw allow from IP to any port P proto tcp
    dockercurl -fsSL https://get.docker.com | sudo sh · sudo usermod -aG docker $USER · publish as -p 127.0.0.1:P:P
    nodenvm install --lts · nvm use 22 · nvm alias default 22
    rubyrvm install 3.4 · rvm use 3.4 --default · rvm list
    pythonpyenv install 3.13 · pyenv global 3.13 · pyenv local 3.12 (per folder)