Back to all articles
VPS & Infrastructure2026-10-01

Managed KVM VPS: First Commands After the Server Is Delivered

Managed KVM VPS: confirm the hypervisor, create an SSH-key user, disable root login, and turn on the firewall, fail2ban, and automatic updates.

A managed KVM VPS is a virtual machine with its own kernel and isolated CPU, memory, and disk, with the security setup done before the application goes live. Whoever receives root access still has to validate the environment and lock down SSH. These are the first commands, on Ubuntu 22.04 or 24.04.

How this compares with shared hosting is in managed VPS or shared hosting. The plan where engineering does this setup is the KVM VPS.

1. Confirm the hypervisor is KVM

systemd-detect-virt
free -h
nproc
lsblk

systemd-detect-virt should print kvm. free -h and nproc show the plan's RAM and vCPUs. lsblk lists the disk. If the command prints openvz or lxc, the server does not have its own kernel and several steps below do not apply.

2. Update and create the operator user

Log in as root only for this first session.

apt update && apt upgrade -y
adduser deploy
usermod -aG sudo deploy

On your laptop, create a key if you do not have one and copy it to the server:

ssh-keygen -t ed25519 -C "deploy@company"
ssh-copy-id deploy@VPS_IP

Open a second terminal and confirm that ssh deploy@VPS_IP logs in without a password. Only then continue. Closing root before that test locks you out of the server.

3. Disable root login and passwords

sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl reload ssh
sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication) '

sshd -t checks the file. If it reports an error, do not reload the service. sshd -T prints the values in effect: both must show no. If passwordauthentication is still yes, a file in /etc/ssh/sshd_config.d/ (such as 50-cloud-init.conf) is winning, because it is read before the rest of sshd_config; fix the line there too. Keep the current session open and test the key login from another terminal.

4. Firewall, fail2ban, and automatic updates

sudo apt install -y ufw fail2ban unattended-upgrades
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

On Ubuntu, the package already enables the SSH jail in /etc/fail2ban/jail.d/defaults-debian.conf. To set the retry limit and ban time, create /etc/fail2ban/jail.local:

[sshd]
enabled = true
maxretry = 5
bantime = 1h
sudo systemctl enable --now fail2ban
printf 'APT::Periodic::Update-Package-Lists "1";\nAPT::Periodic::Unattended-Upgrade "1";\n' | sudo tee /etc/apt/apt.conf.d/20auto-upgrades
sudo systemctl enable --now unattended-upgrades
sudo timedatectl set-timezone UTC

ufw status must show the OpenSSH rule as ALLOW. Without it, the next login will not connect.

5. What to check before deploying the application

df -h
timedatectl
sudo fail2ban-client status sshd

Free disk, the right timezone, and the sshd jail active. The application comes after that: a service user without sudo, the app port behind Nginx, and backups off this machine. CPU and disk monitoring is in Grafana on a VPS.

When the first login breaks

  • SSH refused after passwords are turned off: the public key was not in the new user's authorized_keys. Use the provider console. Do not restart sshd again in the dark.
  • ufw status without the OpenSSH rule on ALLOW drops the session on the next reload. Allow SSH before ufw enable.
  • A virtualization check other than kvm means the plan is not the isolated KVM this guide assumes. Stop and confirm the product before you continue.

Conclusion

These commands leave the KVM VPS with one user, a key, a firewall, and security updates. That is the minimum before any site is published. On a managed VPS this first day is already done, and the team keeps root for the application.

Managed KVM VPS

ExpertCore provisions and runs the VPS: isolated KVM, backups, and engineering support.

See VPS plans