A new Ubuntu server needs a reliable way back in before it starts running applications. Initial setup on Ubuntu 26.04 LTS brings packages up to date and gives a named administrator key-based SSH access from a known address, with sudo available when a command needs it.

UFW filters traffic at the server. For a cloud VM, the provider firewall also needs to allow TCP port 22 from the administrator's address. A fixed office or VPN exit address makes a source rule easier to maintain when the administrator works from different networks.

Ubuntu normally schedules automatic security updates. The initial APT upgrade applies updates that are already available, and the unattended-upgrade schedule keeps checking for eligible updates after the handoff.

Steps to complete initial setup for an Ubuntu server:

Start at the console of a fresh Ubuntu Server install on a trusted network as a user who can run sudo. Use the console through the automatic-update checks and keep it available until the new login works. The server needs OpenSSH on TCP port 22 with password logins enabled, UFW with its fresh-install policy, and Ubuntu's default automatic-update settings.

Have the server's IPv4 address and the SSH client's IPv4 source address as the server will see it. If the client connects through a VPN or NAT, that source is the exit address. The client needs OpenSSH, ssh-copy-id, and an existing ~/.ssh directory.

If your server image disables SSH password logins, stop here and leave that policy in place. Your provider's key authorization mechanism is the way to install the key before connecting.

  1. Read the server's Ed25519 host key fingerprint on the trusted server console.
    $ ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

    The SHA256: value identifies the server when the client connects for the first time.

  2. Refresh the server's APT package index.
    $ sudo apt update

    If an Ubuntu repository fails to refresh, resolve the mirror or network problem before upgrading packages.

  3. Apply available upgrades to the installed packages.

    Package upgrades can restart services, and a required reboot interrupts access. If /run/reboot-required exists after the upgrade, restart from the console before continuing.

    $ sudo apt upgrade

    APT shows the packages it will change before asking to proceed. Ubuntu package management covers the upgrade process.

  4. Check which packages are still upgradable.
    $ apt list --upgradable

    An empty list means APT sees no outstanding upgrades. If APT deferred updates, check whether the packages are phased before assuming an upgrade failed.

  5. Create a local account for the new administrator with your chosen username in place of adminops.
    $ sudo adduser adminops

    Set a strong password for the new account when prompted. You can leave the profile fields blank and confirm when the details are correct.

  6. Add your new administrator to the sudo group, replacing adminops with their username.

    Membership allows the account to run commands as root after authentication. Use this group only for a user trusted with full administration of the server.

    $ sudo adduser adminops sudo
  7. Confirm that UFW is inactive on the new server.
    $ sudo ufw status

    Stop before changing UFW if the firewall is active, has saved rules, or uses an incoming policy other than deny. A fresh install shows Status: inactive.

  8. Check for firewall rules saved while UFW is inactive.
    $ sudo ufw show added

    The fresh configuration shows (None). Enabling UFW also applies any saved rules.

  9. Confirm that UFW's default incoming policy drops traffic.
    $ grep '^DEFAULT_INPUT_POLICY=' /etc/default/ufw

    The fresh configuration shows DEFAULT_INPUT_POLICY="DROP".

  10. Allow TCP port 22 from your client's IPv4 source address as seen by the server, replacing 192.0.2.20.
    $ sudo ufw allow from 192.0.2.20 to any port 22 proto tcp

    Ubuntu's firewall documentation covers UFW rules and source addresses.

  11. Enable UFW after adding the SSH rule.

    A wrong source address can lock out new SSH sessions. If the new login fails, use the server console to run sudo ufw disable and correct the SSH rule before enabling UFW again.

    $ sudo ufw enable

    UFW reports Firewall is active and enabled on system startup.

  12. Check the live default policy for incoming connections.
    $ sudo ufw status verbose

    The Default line should include deny (incoming).

  13. Check that the live SSH rule allows only your chosen source address.
    $ sudo ufw status

    The only rule should show 22/tcp and ALLOW, with your client's source address in the From column.

  14. Check that the unattended-upgrade timer is enabled.
    $ systemctl is-enabled apt-daily-upgrade.timer

    The expected result is enabled.

  15. Check that APT is configured to run unattended upgrades daily.
    $ apt-config dump | grep '^APT::Periodic::Unattended-Upgrade'

    The setting should show "1". If either automatic-update check fails, follow Ubuntu's automatic updates instructions before handing off the server.

  16. Generate a dedicated Ed25519 key in the SSH client's terminal using an unused basename.

    Both ~/.ssh/ubuntu-server and ~/.ssh/ubuntu-server.pub must be unused. If either exists, choose a new basename and use it for generation, copy, and login. The passphrase protects the private key, which stays on the client.

    $ ssh-keygen -t ed25519 -f ~/.ssh/ubuntu-server -C ubuntu-server
  17. Copy the new public key from the client to your new administrator's username at your server's IPv4 address, replacing the key basename if you changed it and substituting your own values for adminops and 192.0.2.10.

    At the first SSH trust prompt, accept only if the displayed Ed25519 fingerprint matches the value from the trusted console. Stop if you cannot match it. Trusting the wrong host can expose the account password you type next.

    $ ssh-copy-id -i ~/.ssh/ubuntu-server.pub adminops@192.0.2.10

    The copy can prompt for the new account's password and should report one key added.

  18. Start a fresh key-only SSH session from your allowed client using the private key you generated, the new administrator's username, and your server's IPv4 address in place of the example values.
    $ ssh -S none -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -i ~/.ssh/ubuntu-server adminops@192.0.2.10

    The -S none option disables connection sharing, so an existing session cannot make the check pass. The client may ask for the private key's passphrase. A successful login opens the new administrator's shell.

  19. Confirm sudo access from the new administrator's SSH session.
    $ sudo whoami
    [sudo: authenticate] Password:
    root

    The sudo prompt uses the new account's password. The result root confirms that the new administrator can elevate privileges after logging in.

Share this guide