The First 10 Things to Configure on a New Ubuntu VDS
After buying a new Ubuntu VDS, you need to complete a few basic configurations instead of starting to use the server right away. System updates, a separate user account, SSH security, a firewall and brute-force protection protect you against the automated scans and password attempts an internet-facing server faces in its first minutes.
This guide walks you through the initial Ubuntu VDS setup in order, command by command. The steps apply to Ubuntu 22.04 LTS and 24.04 LTS. By the end of the guide, your server will be more secure and ready for installing a website, application or service.
- β Update the system
- β Create a new sudo user
- β SSH security
- β Firewall configuration
- β Install Fail2Ban
- β Automatic updates
- β Time and NTP settings
- β Check system resources
- β Review unnecessary services
- β Get the server ready for use
- 1. Update the System
- 2. Create a New Sudo User
- 3. Set Up SSH Key Login
- 4. Configure SSH Security Settings
- 5. Install the UFW Firewall
- 6. Install Fail2Ban
- 7. Check the Time Zone and NTP Settings
- 8. Enable Automatic Security Updates
- 9. Check Server Resources
- 10. Check Open Ports and Services
- Bonus: An Even More Secure Server
- Conclusion
What You Need Before You Start
Before moving on to what to do after getting your VDS, make sure you have the following ready:
- A VDS server with Ubuntu 22.04 LTS or 24.04 LTS installed
- The server's IP address and the initial login details sent by your provider (usually the
rootuser and a password) - An SSH client: Terminal on Linux and macOS, PowerShell (OpenSSH) on Windows 10/11
If you don't have a VDS server yet, you can explore the Netiyo VDS solutions that fit your needs.
Make the first connection to the server as the root user. Replace SERVER_IP with your server's real IP address:
ssh root@SERVER_IP
On the first connection, you're asked to confirm the server's fingerprint. Type yes to continue, then enter the root password. The username and SERVER_IP values in this guide are examples; don't forget to replace them with your own values.
Update the Ubuntu System
A freshly installed VDS image may not include security patches released after it was prepared. Refreshing the package list and bringing installed packages up to date is the most basic precaution you can take against known vulnerabilities. The commands are written with sudo; they also work as-is if you're connected as root.
sudo apt update
sudo apt upgrade -y
sudo apt updatedownloads the latest version information from the package repositories. It doesn't change any packages yet.sudo apt upgrade -yupgrades installed packages to their new versions. The-yparameter automatically answers "yes" to confirmation prompts.
After updating, you can use this command to clean up dependencies that are no longer needed:
sudo apt autoremove -y
This command frees up disk space by removing libraries no longer used by other packages and old kernel packages.
If the kernel was also updated, you need to restart the server for the new version to take effect. The initial setup stage, when you're not running any services yet, is the best time for this.
sudo reboot
Wait about a minute and you can reconnect with the same IP address.
Create a New Sudo User
Most VDS servers are delivered with a root account. The root user has unlimited privileges on the system; a single mistyped command can damage the system irreversibly. In addition, the "root" username is known to everyone and is the first target attackers try.
Creating a user with limited privileges for daily tasks and running administrative commands with sudo both reduces the risk of mistakes and ensures privileged actions are logged.
adduser username
usermod -aG sudo username
adduser usernamecreates the new user and their home directory. You're asked to set a strong password. You can leave other fields such as name and phone blank and press Enter to skip them.usermod -aG sudo usernameadds the user to thesudogroup. The-a(append) parameter preserves the user's existing groups, and-Gspecifies the group to add.
To confirm the account works, switch to the new user and test sudo privileges:
su - username
sudo whoami
If the output of the last command is root, sudo privileges are working correctly. You can type exit to return to the root session.
Set Up SSH Key Login
An SSH key is a key pair used instead of a password. The public key part of the pair is uploaded to the server, and the private key part stays only on your computer. During the connection, the server cryptographically verifies that you have the private key. Because there's no password to guess, this method is far more resistant to brute-force attacks.
Run the following commands on your own computer, not on the server. We recommend the ed25519 algorithm because it's modern, short and secure.
ssh-keygen -t ed25519
The command asks for the file location; you can accept the default (~/.ssh/id_ed25519). We then recommend setting a passphrase; it prevents the key from being used directly even if the private key file is stolen. At the end, two files are created: the private key id_ed25519 and the public key id_ed25519.pub.
Transfer the public key to your new user's account:
ssh-copy-id username@SERVER_IP
This command connects with the user's password and adds the public key to the ~/.ssh/authorized_keys file on the server.
For Windows users
On Windows 10 and 11, you can use the OpenSSH client from PowerShell. The ssh-keygen -t ed25519 command above works the same in PowerShell for generating the key. Since ssh-copy-id isn't available on Windows, you can transfer the public key with the command below:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh username@SERVER_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
After the transfer, test that you can log in with the key in a new terminal window:
ssh username@SERVER_IP
If the connection opens without asking for the user's password (only the passphrase is asked if you set one for the key), the SSH key setup is complete.
Never share your private key with anyone. Don't send the id_ed25519 file by email, messaging app, support ticket or any Git repository. Only the public key with the .pub extension is added to the server. If the private key is compromised, whoever holds it can log in to your server; in that case, delete the relevant line from the authorized_keys file and create a new key pair.
Configure SSH Security Settings
Ubuntu SSH security relies on the settings in the sshd_config file, which determine who can access the server remotely and by which method. In this step, we'll disable direct root login and allow connections only with SSH keys.
Before disabling root access, make sure the following three items work:
- The new sudo user has been created.
- You can log in to the server with this user via SSH key.
- The
sudocommand works for this user.
Don't disable root login and password login until all three are verified. Keep your current SSH session open and do the tests in a separate terminal window. Otherwise, you may lose access to the server completely.
Open the configuration file to edit it:
sudo nano /etc/ssh/sshd_config
In the nano editor, use Ctrl + O and Enter to save changes and Ctrl + X to exit the editor. Find the following lines in the file and change them as shown. If a line starts with #, it's a comment; you need to remove the sign.
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
PermitRootLogin nodisables direct SSH login as root. Attackers can no longer target the best-known username.PubkeyAuthentication yesallows SSH key login. It's on by default in Ubuntu; still, stating it explicitly makes the configuration readable.PasswordAuthentication nodisables password login. Only people with the private key can connect, and password-guessing attacks become pointless. Apply this line only after successfully testing key login.
After saving the file, test the configuration syntax:
sudo sshd -t
If the command produces no output, the configuration is error-free. If there's an error, it's shown with the file name and line number; don't continue without fixing it. If the test passes, load the settings into the SSH service without dropping connections:
sudo systemctl reload ssh
Now, without closing your current session, open a new terminal window and connect with ssh username@SERVER_IP. If the connection succeeds, the settings are working correctly. When you try to connect as root, you should get a Permission denied error.
On Ubuntu 22.04 and later, files in the /etc/ssh/sshd_config.d/ directory are read before the main file, and if the same setting is defined there, its value takes effect (for example 50-cloud-init.conf on cloud images). You can check that your settings are really applied with the command below.
sudo sshd -T | grep -e permitrootlogin -e passwordauthentication -e pubkeyauthentication
Install the UFW Firewall
UFW (Uncomplicated Firewall) is a firewall tool that lets you manage Ubuntu's network filtering infrastructure with simple commands. Its default policy is to deny incoming connections and allow outgoing ones. You open only the ports you need. This approach is one of the cornerstones of Ubuntu server security.
If you enable UFW without allowing the SSH port, your current connection may drop and you may not be able to connect to the server via SSH again. That's why you should add the SSH rule first, then enable the firewall. If you changed the SSH port from 22 to another value, you should allow your own port instead of OpenSSH.
sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose
sudo apt install ufw -yinstalls UFW. It's usually preinstalled on Ubuntu; if it's installed, the command doesn't change anything.sudo ufw allow OpenSSHadds the rule needed for SSH connections.sudo ufw enablestarts the firewall and makes it run automatically every time the server boots. At the "Command may disrupt existing SSH connections" warning, you can confirm withysince you've added the SSH rule.sudo ufw status verboseshows the active rules and default policies. You should see theDefault: deny (incoming), allow (outgoing)line.
If you'll use a web server
Only open ports 80 (HTTP) and 443 (HTTPS) if you'll run a web server such as Nginx or Apache on the server. Every open port increases the attack surface, so don't allow ports you won't use.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Install Fail2Ban
Every server exposed to the internet soon encounters bots trying passwords over SSH. Fail2Ban monitors system logs and blocks, for a set period, IP addresses that make many failed login attempts in a short time. That way, brute-force attempts are neutralized and don't needlessly consume server resources or fill your log files.
sudo apt install fail2ban -y
To start the service right away and enable it to run automatically every time the server boots:
sudo systemctl enable --now fail2ban
Confirm that the service is running:
sudo systemctl status fail2ban
You should see active (running) in the output. Press q to exit the status screen. The Ubuntu package comes with SSH protection (the sshd jail) enabled by default; you can use this command to see blocked IPs and the number of attempts:
sudo fail2ban-client status sshd
The default settings provide sufficient protection for an initial setup. Custom jail configurations such as the ban duration, retry limit and trusted IP list are an advanced topic and the subject of a separate guide.
Check the Server's Time Zone and NTP Settings
The server clock is the basis for log records, scheduled tasks and security investigations. If the time is wrong, you can't accurately determine when an event happened, and cron jobs don't run when you expect. Time-dependent mechanisms such as SSL certificate validation and one-time verification codes may also fail.
View the current time and time zone information:
timedatectl
In the output, you'll see the Local time, Time zone, System clock synchronized and NTP service lines. VDS servers usually come set to UTC. Leaving the server on UTC is also a valid choice; what matters is that the time is consistent and correct. If you want to follow logs and scheduled tasks in your local time (for example Turkey time), change the time zone:
sudo timedatectl set-timezone Europe/Istanbul
Then check that time synchronization (NTP) is working:
timedatectl status
You should see System clock synchronized: yes and NTP service: active. Ubuntu does this by default with systemd-timesyncd. If NTP is off, you can turn it on with this command:
sudo timedatectl set-ntp true
Enable Automatic Security Updates
Security vulnerabilities are discovered all the time, and patches are often released quickly. Instead of checking the server manually every day, the unattended-upgrades package can download and apply security updates on its own in the background. That way, a known vulnerability doesn't stay open for days without you noticing. The package is usually preinstalled on Ubuntu server images; if it isn't, you can install it with this command:
sudo apt install unattended-upgrades -y
Run the configuration wizard to enable the feature:
sudo dpkg-reconfigure --priority=low unattended-upgrades
On the screen that opens, select Yes for "Automatically download and install stable updates?" and press Enter. In its default configuration, Ubuntu usually applies only security updates and doesn't restart the server on its own. You can check that the setting was created in this file:
cat /etc/apt/apt.conf.d/20auto-upgrades
If the file contains the lines APT::Periodic::Update-Package-Lists "1"; and APT::Periodic::Unattended-Upgrade "1";, automatic updates are enabled.
On servers running in production or that are business-critical, plan the update policy separately. Automatic updates to the database, web server or application dependencies can cause unexpected incompatibilities. Try important updates in a test environment first, set a maintenance window and define a method for updates that require a restart.
Check Server Resources
Before installing applications on the server, confirm that the CPU, RAM and disk resources are configured as you expect. Noting the idle values at initial setup gives you a point of comparison when investigating problems later.
RAM usage
free -h
The command shows total, used and free RAM and swap space in readable units (-h). The column you really need to look at is available; it gives the estimated amount of memory applications can use. If swap is constantly filling up, the server doesn't have enough RAM.
Disk usage
df -h
Lists the total size, used space and usage percentage (Use%) of mounted disk partitions. Regularly monitor the usage of the root / partition; when the disk is full, services can't write files and logs may be lost.
lsblk
Shows the disks and partitions attached to the server in a tree structure. You can confirm here that the disk size you bought shows up correctly in the system.
CPU and system load
uptime
The output gives how long the server has been up, the number of logged-in users and the load average values. The three numbers show the average load over the last 1, 5 and 15 minutes respectively. Compare these values with the server's number of CPU cores:
nproc
For example, on a 2-core server, a load average staying above 2 for a long time shows that the processor is working hard and jobs are waiting in line.
top
top lists running processes live by CPU and RAM usage. In the %Cpu(s) line at the top, id shows the share of idle CPU and wa shows disk wait. Press q to exit.
A more readable alternative: htop
htop offers a colorful, interactive interface compared with top. It shows CPU cores and memory usage with bar graphs and lets you select and manage processes with the arrow keys. It may not be installed by default on Ubuntu:
sudo apt install htop -y
htop
You can use the q or F10 key to exit.
Check Open Ports and Running Services
Every service that can be reached from outside a server is a potential way in. For VDS security, you need to know which services are running and which ports they listen on. By reviewing this list once after the initial setup, you'll know what your server's "normal" state looks like.
sudo ss -tulpn
The command lists the network ports in a listening state. The parameters mean the following: t TCP, u UDP, l listening connections, p the related process, and n shows ports and addresses as numbers instead of names.
- Addresses such as
0.0.0.0:22or[::]:22show that the service is reachable from all network interfaces. - Addresses such as
127.0.0.1or127.0.0.53show that the service is reachable only from the server itself. For example, it's normal forsystemd-resolvedto listen on 127.0.0.53. - The process name in the last column shows which program opened the port. On a clean installation, usually only
sshdis exposed to the outside.
Now list the running services:
systemctl --type=service --state=running
This command shows the systemd services actively running at that moment. If you see a service you don't recognize in the list, don't shut it down right away; first find out what it does.
Stopping services you don't use reduces the attack surface, but don't disable a service without finding out what it does. SSH, network configuration and system services are needed for the server to run. There may also be services used by your hosting provider's management tools. First look at the output of systemctl status service-name and search for the service name in a reliable source.
If you're sure a service really is unnecessary, you can both stop it and disable it at boot:
sudo systemctl disable --now service-name
To undo this, you can use enable instead of disable in the same command. An unnecessary open port can become a way into your server if a vulnerability is found, even if the service isn't used. That's why you should regularly review your open ports together with your UFW rules.
Bonus: Make Your Server Even More Secure
Once you've completed the ten steps, your server reaches a good baseline level of security. Since security isn't a one-time task, we recommend keeping up the following habits:
- Regular backups: Store backups in a location outside the server and test restoring in advance.
- Monitoring: Monitor CPU, RAM, disk and service status, and get alerts when critical thresholds are exceeded.
- Using SSH keys: Use a separate key for each person and device, and remove the keys of people whose access has been revoked from the
authorized_keysfile. - Strong user policies: Use long, unique passwords, avoid shared accounts and give sudo privileges only to the users who need them.
- Log monitoring: Check logs such as
/var/log/auth.logand thejournalctloutput from time to time to spot unusual login attempts. - Closing unnecessary ports: Update your open ports and firewall rules as you install or remove services.
- Keeping applications up to date: The web server, database and applications you install are as important as the operating system; old versions are one of the most commonly used attack paths.
Once you've prepared the basics of your Ubuntu VDS, if you want to set up your own VPN server, take a look at our WireGuard setup guide.
Conclusion
In this guide, you applied the basic steps of setting up an Ubuntu server. You updated the system, created a user with sudo privileges instead of root, set up SSH key login and tightened the SSH settings. You restricted network access with UFW, added protection against brute-force attempts with Fail2Ban, verified the time and NTP settings and turned on automatic security updates. Finally, you checked the server's resources, open ports and running services.
Setting up an Ubuntu VDS isn't just about getting the operating system running; security and basic system settings need to be done correctly. Completing what needs to be done after getting a VDS from the start prevents most of the access loss, security breaches and performance problems you might otherwise run into later. Your server is now ready for your website, application or your own services.
If you want to create an Ubuntu-based server and host your own applications, you can explore Netiyo VDS plans.
Explore VDS Plans