HomeBlog
Initial Ubuntu VPS Setup with SSH and UFW

Initial Ubuntu VPS Setup with SSH and UFW

Your new server is ready, and you want to install your website right away. A few preparation steps will help you do it with clear access and a recovery plan.

We will show the basic setup of a VPS running Ubuntu 24.04 LTS. This guide is for a new server; production machines with running services need a separate change plan. The commands have been checked against the documentation but not run on your VPS.

What to prepare before setting up your VPS

You need the public IP address, the initial user and the login method from your provider. The image may give you root or a regular account with sudo. Use exactly the credentials you received for the service.

Before changing SSH and the firewall, find out how to open the emergency console or contact support. Do not assume every control panel offers the same recovery method. Keep your initial SSH session open until all checks are complete.

“Calm work starts with a clear plan.”

In the examples, admin is the new user and 203.0.113.10 is a placeholder IP for documentation. Replace the address with your own. If SSH listens on a non-standard port, add -p with its number.

On your computer, run ssh [email protected] or use the user you were given. On the first login, compare the server key fingerprint with a trusted source from your provider, if one is available.

Do not ignore a warning that a known server's key has changed: first find out whether the server was reinstalled. Once access is confirmed, move on to checking the system.

Check Ubuntu and install updates

The commands cat /etc/os-release and uname -r show the OS and kernel versions. Write them down: this will help you match your server to guides. You can list running services with systemctl --type=service --state=running.

On a new server, update the package lists and packages:

sudo apt update
sudo apt upgrade

If you are working as root, you can omit sudo. Read the proposed changes before confirming: some packages restart services. Do not update a running application without considering its availability.

If the update requires a reboot, schedule it and check access after the restart. The presence of the /var/run/reboot-required file may indicate this need, but it does not replace reading the package manager's messages.

After logging in again, check the system once more. Next, create an account for everyday work so that you do not run everything as root.

Create a user with sudo

In the initial administrative session, run:

sudo adduser admin
sudo usermod -aG sudo admin
id admin

Choose a strong password for the user: sudo may ask for it even when you log in with an SSH key. The id output should include the sudo group. Creating a user does not yet copy the initial account's keys to it.

Open a second terminal and test logging in as admin. If the image does not allow password login, first add the public key through the initial session. Do not weaken SSH protection just to make copying easier.

After logging in, run sudo -v and sudo whoami. The second command should show root. This confirms the right to perform administrative actions, while your normal session remains a user session.

If the check fails, go back to the initial window and check the groups and sudo settings. Keep both sessions open until you finish.

Set up SSH keys on Ubuntu

On your own computer, create a key if you do not have a separate one yet:

ssh-keygen -t ed25519

Add a passphrase and do not overwrite an existing key by accident. The public file has the .pub suffix; the private key stays with you. You do not need to upload it to the VPS or send it to support.

If password login is available, copy the public key with ssh-copy-id [email protected]. If this command is not available, add the contents of the .pub file to /home/admin/.ssh/authorized_keys through a trusted session.

The .ssh directory must be owned by admin with permissions 700, and authorized_keys must have 600. Check the owner and permissions if the server rejects the key. Do not give other users access to the private key.

In a separate terminal, run ssh -o PreferredAuthentications=publickey [email protected]. Make sure the new login works and sudo is available. After that, you can consider restricting password authentication.

Check SSH changes before applying them

On Ubuntu, the configuration may include files in /etc/ssh/sshd_config.d/*.conf. Before editing, save copies of the files you change and check the effective settings with sudo sshd -T. Keep in mind that Match blocks may depend on the user and address.

If you disable password login and direct root access, first make sure admin can log in with a key. For a key-only setup, check PasswordAuthentication, KbdInteractiveAuthentication and PermitRootLogin.

After making changes, run sudo sshd -t. Only if it succeeds, apply sudo systemctl reload ssh and test a separate login again. If there is an error, restore the configuration copy from the initial session.

Allow SSH before enabling UFW

Setting up Ubuntu Server includes network rules. UFW manages the system firewall; your provider may also have a separate network firewall, which is checked separately.

For standard SSH on TCP 22:

sudo ufw allow 22/tcp
sudo ufw status verbose
sudo ufw enable
sudo ufw status numbered

If SSH uses a different port, allow that port instead of 22 first. Before enable, make sure the rule exists. Do not close the current window until a new SSH connection has passed the check.

“Reliability is made of small, verified steps.”

If you lose access, use your provider's console: review the rules and fix the port. To restore access temporarily from the console, you can disable UFW and then set the correct restrictions again.

Open website ports after installing the corresponding service. For example, Nginx needs TCP 80 and 443; a database often does not need public access at all.

Check the time and server readiness

The timedatectl command shows the time zone and synchronization status. You can leave a server on UTC; if you need local time, check that your zone is available with timedatectl list-timezones.

The time zone does not replace clock synchronization. Consistent time matters for logs, certificates and scheduled tasks. After the setup, check that logs show the expected time.

Before installing your application, confirm:

  • a separate admin login with an SSH key;
  • sudo works;
  • the correct SSH port in UFW and your provider's rules;
  • an available recovery method;
  • up-to-date packages and a clear system time.

The basic VPS setup is now complete. Save notes about your Ubuntu Server setup and SSH check before moving on to Docker or Nginx; to choose a configuration, open VPS on Ubuntu. If you are still deciding on resources, read “How to Choose a VPS for a Website or Application”.

Initial Ubuntu VPS Setup with SSH and UFW
vds

You might be interested in Fotbo's VPS server

View