Within minutes of ordering a VPS, your new server is on the internet, and within the first hours automated scanners around the world start probing port 22. That does not mean your server is special; every address that goes online is scanned routinely. This is why the first 30 minutes after buying a VPS decide how secure and manageable the machine will be for months afterwards. In this guide you will find what to do, why, and with which command, for an Ubuntu or Debian based Linux VPS.
The steps are sequential and each takes a few minutes. Commands are written for Ubuntu and Debian; on AlmaLinux and Rocky Linux the package manager and firewall tool differ, but the logic is identical. If you are still choosing a server, read our checklist of 12 things to check when buying a VPS first.
After the order, the server's IP address, username and initial password are sent to you, and you can also find them in the Client Area. Before you begin, prepare the following:
ssh command.The last point matters: when changing security settings there is always a chance of locking yourself out. Knowing from the start that the panel console works as a fallback lets you apply the steps with confidence.
Make the first connection from your own computer. The server will ask you to confirm its fingerprint the first time; this is normal.
ssh root@SERVER_IP_ADDRESS
Once inside, quickly check the system, its resources and the open ports:
cat /etc/os-release
uname -r
nproc
free -h
df -h
ss -tulpn
The goal is to confirm that the resources you ordered (cores, RAM, disk) are what you got, and that no unexpected service is listening. On a clean image, usually only SSH listens.
Ready-made images may have been built days or even weeks ago. Your first job is to refresh the package list and apply security patches.
apt update
apt full-upgrade -y
apt autoremove -y
If the kernel was updated, you may need to reboot. Since no live service runs on the machine yet, now is the cheapest time to do it. After the reboot, reconnect with the same SSH command. Enabling automatic security updates also prevents patches from piling up unnoticed:
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
Working as root every day creates two problems: a typo can affect the whole system, and attackers do not have to guess a username because root exists everywhere. Create a user in your own name and add it to the sudo group:
adduser deploy
usermod -aG sudo deploy
Avoid very common names such as admin, test or ubuntu. This is not protection by itself, but it reduces noise. Before closing root access, test the new user in a second terminal; do not touch root login until you have seen it work.
With password login, anyone on the internet can try an unlimited number of guesses. With key-based login, an attacker needs your private key. Generate a key pair on your own computer:
ssh-keygen -t ed25519 -C "vps-deploy"
ssh-copy-id deploy@SERVER_IP_ADDRESS
If ssh-copy-id is not available on Windows, append the contents of .ssh/id_ed25519.pub to /home/deploy/.ssh/authorized_keys on the server; the directory permissions should be 700 and the file permissions 600. After confirming key login works from a new terminal, tighten the SSH settings:
sudo nano /etc/ssh/sshd_config.d/99-hardening.conf
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
LoginGraceTime 30
Before applying, check the syntax and then reload the service. Keep your current session open and test the new setting from a second window:
sudo sshd -t
sudo systemctl reload ssh
On some distributions the service is called sshd. For more SSH hardening options, see our Linux server security and SSH guide.
Deploy your Linux VPS in Istanbul
KVM virtualization, a 1 Gbps port, and console and rescue mode access from the Client Area.
Explore VPS plansThe firewall logic is simple: deny everything incoming by default and allow only the ports you need. On Ubuntu the easiest tool is UFW. Do not enable the firewall before adding the SSH rule, or you will lock yourself out.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose
If you will run a web server, also open ports 80 and 443:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Do not expose database ports (3306, 5432, 6379) to the internet. If your application runs on the same server, these services only need to listen on 127.0.0.1. If remote access is required, limit the source to a single IP address:
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp
One warning if you plan to use Docker: Docker adds its own iptables rules for published ports and can bypass UFW rules. Binding container ports to the local interface only, such as 127.0.0.1:8080:80, is a good habit. See our guide to installing Docker Compose on an Ubuntu VPS for the setup.
UFW leaves a port open; Fail2ban reads the logs, detects addresses that repeatedly fail to log in to that port and blocks them temporarily. Even with key-based login it reduces log noise and pointless load.
sudo apt install -y fail2ban
sudo nano /etc/fail2ban/jail.local
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
[sshd]
enabled = true
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
If you connect from a fixed address, you can add it to the ignoreip line so you never block yourself by accident. To unblock an address, use fail2ban-client set sshd unbanip ADDRESS.
Correct timestamps in your logs make a big difference when troubleshooting. Clock synchronization is ready on most modern images, but verify it and adjust if necessary:
timedatectl
sudo timedatectl set-timezone Europe/Istanbul
sudo hostnamectl set-hostname web01
The output of timedatectl should show System clock synchronized: yes. The hostname should be consistent, especially if you will send email and define a reverse DNS (rDNS) record.
On a VPS with little RAM, the kernel may kill processes when memory runs out. If you will run a busy application, a small swap file adds a safety margin; swap does not replace memory, it only cushions sudden spikes. Check the current state first:
swapon --show
free -h
If there is no swap and you need it, you can create a 2 GB file like this:
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
Adjust the swap size to your disk and workload. On database servers, constantly high swap usage is a sign that RAM is insufficient and you should consider a larger plan.
A backup of the clean state gives you a reference point to return to if a later setting goes wrong. An optional paid Backup Service add-on is available for VPS plans and can be selected at order time. Independently of that, it is good practice to keep the important configuration files separately:
sudo tar czf ~/etc-backup-$(date +%F).tar.gz /etc/ssh /etc/ufw /etc/fail2ban
Copy this archive off the server, to your own computer or separate storage; a backup sitting on the same disk will not save you from a disk problem. For monitoring, three checks are enough to start:
journalctl -p err -b.The list above is the common baseline for everyone. Depending on what you run, add the following:
| Use case | Extra step | Why |
|---|---|---|
| Website / WordPress | Nginx or Apache, Let's Encrypt certificate, regular database backups | It is a public service, so the attack surface is larger |
| Docker applications | Bind ports to 127.0.0.1, use a reverse proxy in front | Docker can bypass UFW rules |
| Mail server | rDNS, SPF, DKIM, DMARC | Inbox delivery reputation depends on them |
| Remote work / development | Access through a VPN such as WireGuard | Keeps management ports off the public internet |
| Database server | Listen on local or private network only, strong passwords | An exposed database port is a common breach path |
A wrong firewall rule or a faulty SSH setting can leave you outside. VPS management is done from the Client Area: open the console in your browser and disable UFW (sudo ufw disable) or revert the SSH setting. The console uses a US keyboard layout, so keep that in mind for passwords with special characters. In a more serious failure, rescue mode lets you reach your files without wiping the disk.
Need more power than a VPS?
Dedicated servers add browser-based KVM console and power controls through the Client Area.
See dedicated server plansAt the end of the 30 minutes you should be able to answer yes to all of the following:
sshd jail is active.This list does not replace a corporate security program; its purpose is to close the most common mistakes on a freshly exposed server within the first hour. After you install your application, version updates, log review and regular restore tests continue as ongoing work. If you see signs of an attack, follow the diagnostic steps in how to tell if you are under a DDoS attack; for protection options, see the DDoS protection information on our site. Support requests are accepted 24/7, and you can reach us through the contact page whenever you get stuck.
What should I do first after buying a VPS?
Confirm in the panel that the server is running and note its IP address, then connect over SSH, update the system, create a sudo user instead of using root, and switch to SSH key login instead of a password.
Is disabling root SSH login mandatory?
It is not mandatory but strongly recommended. The root username is known to everyone, so it is the first target of brute-force attempts; a separate sudo user with key-based login shrinks the attack surface noticeably.
Does changing the SSH port improve security?
Changing the port only reduces noise from automated scanners and does not provide real protection. Real security comes from key-based login, disabling passwords and a blocking layer such as Fail2ban.
Should UFW and Fail2ban be used together?
Yes, they do different jobs. UFW decides which ports are reachable from outside, while Fail2ban temporarily blocks addresses that repeatedly fail to log in to an open port.
What if I lock myself out of the server?
You can use the console in the Client Area to log in and fix the firewall or SSH setting. Rescue mode is another way to reach your files without wiping the disk.
Should I wait before taking the first backup?
No. Even before there is real data on the server, a snapshot or backup of the clean initial state gives you a reference point to return to if a later change goes wrong.