Management Guides Getting started
Initial Server Setup on Ubuntu 26.04, Debian 13 and AlmaLinux 10
Nine steps for a new Linux VPS: update, hostname and time, sudo user, SSH keys, key-only login, firewall, automatic updates, swap and a snapshot, with a final verification table.
The first twenty minutes on a new server decide how much trouble it gives you later. This guide takes a freshly created VPS to a safe baseline: updated, with a named sudo user, key-only SSH, a firewall, automatic security updates, a swap file and the correct time. The steps are the same on every distribution; where the commands differ, both are shown.
Commands are given for Ubuntu 26.04/24.04 and Debian 13 (apt) and for AlmaLinux and Rocky Linux 9 and 10 (dnf). They are standard tools from each distribution; this guide is a reference and was not run on a test server for this article.
You need the server's IP address and the root password or SSH key from your provider. Replace YOUR_SERVER_IP and the user name deploy with your own values throughout.
Step 1: log in and update
ssh root@YOUR_SERVER_IP
Some Ubuntu images do not allow root login and give you a user such as ubuntu instead; log in as that user and put sudo in front of the commands below.
# Ubuntu, Debian
apt update && apt full-upgrade
# AlmaLinux, Rocky Linux
dnf upgrade
Images are built weeks or months before you use them, so the first update is often large. If a new kernel was installed, reboot now with reboot and log in again.
Step 2: hostname and time zone
hostnamectl set-hostname web1.example.com
timedatectl set-timezone UTC
timedatectl
UTC keeps log timestamps unambiguous; choose a local zone such as Asia/Ho_Chi_Minh if you prefer. In the output of timedatectl, "System clock synchronized: yes" confirms that time synchronisation is working. If it says no:
apt install systemd-timesyncd && systemctl enable --now systemd-timesyncd # Ubuntu, Debian
dnf install chrony && systemctl enable --now chronyd # AlmaLinux, Rocky Linux
Step 3: create a sudo user
# Ubuntu, Debian
adduser deploy
usermod -aG sudo deploy
# AlmaLinux, Rocky Linux
adduser deploy
passwd deploy
usermod -aG wheel deploy
Choose a strong password. It will not be used for logging in, but sudo asks for it.
Step 4: SSH keys
On your own computer, create a key pair if you do not have one, and copy the public half to the server:
ssh-keygen -t ed25519 -C "you@example.com"
ssh-copy-id deploy@YOUR_SERVER_IP
Windows 10 and 11 include ssh-keygen but not ssh-copy-id. From PowerShell:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@YOUR_SERVER_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Test before going on. Open a new terminal and run:
ssh deploy@YOUR_SERVER_IP
sudo -v
You should get in without being asked for the account password (only the key's passphrase, if you set one), and sudo -v should accept your password. Keep the original root session open until step 5 is verified.
Step 5: disable password and root login
Create the file /etc/ssh/sshd_config.d/00-hardening.conf with this content:
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
OpenSSH takes the first value it finds for each setting, and files in this folder are read in alphabetical order. Cloud images often include a file such as 50-cloud-init.conf containing PasswordAuthentication yes; the 00 prefix makes your file win.
sudo sshd -t
sudo systemctl reload ssh # Ubuntu, Debian
sudo systemctl reload sshd # AlmaLinux, Rocky Linux
Verify:
sudo sshd -T | grep -E "^(passwordauthentication|permitrootlogin)"
Both lines should end in no. Then confirm from a third terminal that ssh deploy@YOUR_SERVER_IP still works. If it does not, fix it from the session that is still open, or from the provider's web console.
Step 6: firewall
# Ubuntu, Debian
sudo apt install ufw
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose
# AlmaLinux, Rocky Linux
sudo dnf install firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
Allow SSH before enabling ufw. Open further ports when you install the service that needs them, for example sudo ufw allow 80,443/tcp or sudo firewall-cmd --permanent --add-service=http --add-service=https for a web server.
Step 7: automatic security updates
# Ubuntu, Debian
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# AlmaLinux, Rocky Linux
sudo dnf install dnf-automatic
sudo systemctl enable --now dnf-automatic.timer
On AlmaLinux and Rocky Linux, edit /etc/dnf/automatic.conf and set apply_updates = yes; by default updates are downloaded and not installed. On version 10, check the package name with dnf search automatic if the commands above are not found.
Step 8: swap file
Many VPS images have no swap. On servers with 4 GB of RAM or less, a small swap file prevents a short memory spike from killing the database.
swapon --show # no output means no swap
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
free -h
Step 9: take a snapshot
In your provider's panel, take a snapshot of the server now. It is a clean baseline to return to if a later installation goes wrong. Snapshots are not a replacement for backups; set those up once the site is running (VPS backup strategy).
Final check
| Item | Command | Expected |
|---|---|---|
| System updated | apt list --upgradable / dnf check-update | Nothing, or very little, listed |
| Time synchronised | timedatectl | System clock synchronized: yes |
| Key login works | ssh deploy@YOUR_SERVER_IP | No account password prompt |
| Passwords and root refused | sudo sshd -T | grep -E "passwordauth|permitroot" | no twice |
| Firewall on | sudo ufw status / sudo firewall-cmd --state | active / running |
| Updates scheduled | systemctl list-timers | grep -E "apt|dnf" | A next run time |
| Swap present | swapon --show | /swapfile listed |
What next
- Go further on security with the VPS hardening checklist.
- Set up the ongoing routine from the VPS management guide and the maintenance checklist.
- Install your stack. This site has guides for most web servers, databases and applications on these distributions.
Frequently asked questions
Do I need to do this if my provider's image is already "secure"?
Yes. Provider images vary: some allow root password logins, most have no firewall rules and no automatic updates. The checks in the table take a minute and tell you what you actually have.
I locked myself out. What now?
Use the web console (sometimes called VNC or serial console) in the provider's panel. It logs you in without SSH, so you can correct the SSH or firewall setting.
Should I change the SSH port?
It is optional. It reduces automated login attempts in the logs and does not replace key-only login.
Which distribution should I pick?
Choose the one your software's documentation targets and that you know best. Ubuntu LTS and Debian have the widest tutorial coverage; AlmaLinux and Rocky Linux follow Red Hat Enterprise Linux and are common with control panels such as cPanel.