# Initial server setup checklist for Ubuntu

> An initial server setup is a short, ordered list of safety steps you run once on a new Ubuntu server before you put anything on it.

URL: https://levelrail.com/learn/server-basics/initial-server-setup-checklist/
Updated: 2026-11-27

The initial setup of a new Ubuntu server is five steps: update, create a sudo user, add your SSH key, turn on a firewall and plan updates. A new server is reachable from the whole internet within minutes of being created, and automated scanners find fresh addresses quickly. The default state is usually root login, whatever the image shipped with, and no firewall. This checklist closes the obvious gaps in a fixed order, before you install an app or put data on the machine.

## How it works

Each step protects the next one, so the order is the point.

1. **Update first.** The image may be months old. Patching before anything else removes known holes.
2. **Create a normal user with sudo.** Daily work happens with limited rights. Elevated rights are requested one command at a time.
3. **Install your SSH key for that user.** Now you can log in without a password, and later you can turn password login off.
4. **Turn on the firewall ([ufw](https://levelrail.com/learn/glossary/#ufw))), with SSH allowed first.** The default policy becomes "deny incoming", so anything you did not open is closed.
5. **Plan updates.** A server that is patched once and forgotten is only safe for a short while.

The risky moments are steps 4 and, later, SSH hardening. Both can cut off your only way in. That is why you keep the first root session open until a second, fresh login proves the new setup works.

## Step 1: Log in and update

```bash
ssh root@203.0.113.10
apt update && apt upgrade -y
```

Replace `203.0.113.10` with your server's address. `apt update` refreshes the package list and `apt upgrade -y` installs updates, answering yes to the prompt.

What you should see: lists of packages being fetched and unpacked, ending back at the prompt. If a kernel update was installed, the system may say a restart is required. Run `reboot` and log back in after a minute.

If your provider gave you a non-root user instead, log in as that user and put `sudo` in front of the apt commands.

## Step 2: Create a sudo user

Follow [Create a sudo user](https://levelrail.com/learn/server-basics/create-a-sudo-user/)). In short:

```bash
adduser deploy
usermod -aG sudo deploy
```

What you should see: `adduser` asks for a password and some optional details, then prints that the user was added. `usermod` prints nothing when it works. The `-aG` flags append the user to the `sudo` group without removing other groups.

## Step 3: Add your SSH key

From your own computer, follow [Log in with SSH keys](https://levelrail.com/learn/server-basics/log-in-with-ssh-keys/)):

```bash
ssh-copy-id deploy@203.0.113.10
```

What you should see: a message that one key was added, and advice to try logging in. Open a new terminal and confirm `ssh deploy@203.0.113.10` works without asking for the account password. If your key has a passphrase, you are asked for that instead, which is expected.

## Step 4: Turn on the firewall

Allow SSH first, then enable. See [Set up a firewall with UFW](https://levelrail.com/learn/server-basics/set-up-a-firewall-with-ufw/)).

> Warning: if you enable UFW before allowing SSH, you can lock yourself out.

```bash
sudo ufw allow OpenSSH
sudo ufw enable
```

What you should see: `Rules updated`, then a prompt warning that enabling may disrupt existing SSH connections. Answer `y`. Because SSH is allowed, your session stays up. If you plan to serve a website, also allow ports 80 and 443 now.

## Step 5: Turn on automatic updates

Read [Keep a server updated](https://levelrail.com/learn/server-basics/keep-a-server-updated/)) and decide how you want patches applied.

## Check it worked

In a new terminal, leaving the root session open:

```bash
ssh deploy@203.0.113.10
sudo ufw status
```

You should log in with your key and no account password. `ufw status` should say `Status: active` and list `OpenSSH` (and its IPv6 twin, `OpenSSH (v6)`) as `ALLOW`. Run `sudo whoami` and it should print `root`, which proves sudo works. Only then close the root session. Once all of this works, harden SSH further.

## Edge cases and gotchas

- **Your provider may have its own firewall.** Many hosts offer a network firewall outside the server. Traffic must pass both it and ufw. If ufw is right and you still cannot connect, check the provider panel.
- **Docker ignores ufw for published ports.** Docker writes its own iptables rules, so a container published with `-p 8080:80` can be reachable even if ufw has no rule for 8080. Plan for that before you run containers.
- **IPv6 needs its own rules.** ufw handles IPv6 when `IPV6=yes` is set in `/etc/default/ufw`, which is the Ubuntu default. If your server has an IPv6 address, confirm the `(v6)` rules appear in `ufw status`.
- **Cloud images may pre-install your key for a default user.** On such images the user is often `ubuntu`. Skipping step 2 is fine if you are happy with that account, but you must still lock down SSH.
- **A pending reboot hides behind a working server.** After kernel updates, the running kernel is still the old one until you reboot. Check for `/var/run/reboot-required`.
- **The clock matters.** Wrong server time makes logs confusing and can break TLS later. Run `timedatectl` and check that `System clock synchronized` says yes.
- **Do not set a weak password "just for now".** The new user's password protects `sudo`. Use a long one even if SSH uses keys.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `Permission denied (publickey)` for the new user | Key was not copied to that user | Run `ssh-copy-id deploy@203.0.113.10` again, or log in as root and fix `~/.ssh/authorized_keys` |
| `deploy is not in the sudoers file` | User missing from the `sudo` group | As root run `usermod -aG sudo deploy`, then log in again |
| Connection hangs after `ufw enable` | SSH rule missing, or a custom SSH port not allowed | Use the provider's web console and run `sudo ufw allow OpenSSH` |
| `E: Could not get lock /var/lib/dpkg/lock-frontend` | Another apt process (often unattended upgrades) is running | Wait a few minutes and retry |
| `ufw: command not found` | ufw is not installed on this image | `sudo apt install ufw`, then allow SSH before enabling |
| Everything works but root still logs in | Root login is not disabled yet | Do that in the next lesson, after confirming key login |
| `E: Unable to locate package` | Package list is stale or the repository is missing | Run `sudo apt update` first, then retry |
| The server asks to restart after upgrades | A new kernel or library was installed | Run `sudo reboot`, wait a minute and log in again |

## Real-world scenario

You create a server at 09:00 and the provider shows its address, 203.0.113.10. You log in as root, run `apt update && apt upgrade -y`, and reboot because a kernel update arrived.

Back in, you create the user `deploy`, add it to the `sudo` group and copy your key with `ssh-copy-id`. From a second terminal you check that `ssh deploy@203.0.113.10` logs in with no password prompt and that `sudo whoami` prints `root`.

Only then do you run `sudo ufw allow OpenSSH` and `sudo ufw enable`. You keep the root session open until a third login still works. The whole job takes about fifteen minutes and leaves a server that nothing else can reach but SSH.

## Quick reference

```bash
apt update && apt upgrade -y
adduser deploy && usermod -aG sudo deploy
ssh-copy-id deploy@203.0.113.10
sudo ufw allow OpenSSH && sudo ufw enable
sudo ufw status
```

## Security and safety notes

- Keep your first session open until a second login as the new user works.
- Allow SSH in the firewall before you enable it.
- If you are locked out, the provider's web console is your way back in.

## Related lessons

- [What is SSH](https://levelrail.com/learn/server-basics/what-is-ssh-and-how-does-it-work/)): how the login you are protecting actually works
- [Create a sudo user](https://levelrail.com/learn/server-basics/create-a-sudo-user/)): the step 2 details
- [Set up a firewall with ufw](https://levelrail.com/learn/server-basics/set-up-a-firewall-with-ufw/)): rules beyond SSH
- [Keep a server updated](https://levelrail.com/learn/server-basics/keep-a-server-updated/)): patches after day one

## Next

Close the weakest door with [Disable SSH password login](https://levelrail.com/learn/server-basics/disable-ssh-password-login/)).

## Frequently asked questions

### Why should I stop using root on a new server?

Root can change or delete anything, and attackers target the root account first. A normal user with sudo limits the damage from mistakes and gives you a clearer audit trail.

### Do I need to repeat this for every server?

Yes. Each new server starts with the provider defaults, so run the same checklist every time. A saved note or script makes it quick.

### Why does the order matter?

Each step depends on the one before. If you enable the firewall before allowing SSH, or close root login before your new user works, you can lock yourself out.

### The provider created a user for me already. Do I still need a new one?

Many images ship a default user such as ubuntu with sudo and your key already installed. You can use it, but check that it is the account you want to keep and that password login is off.
