Secure your new VPS
Update the system, create a sudo user, log in with SSH keys, turn on a firewall (ufw), enable automatic security updates and install fail2ban. Windows tips included.
- Difficulty:
- Intermediate
- Time:
- 20 minutes
On this page
A new VPS is reachable from the whole internet, and bots start guessing passwords within minutes. Spend 20 minutes on these steps right after your first login. The commands are for Ubuntu and Debian; notes for other systems are included.
Keep your current SSH session open while you change SSH or firewall settings, and test with a second session before logging out. If you do lock yourself out, use the web console on your VPS page (billing panel → Servers → Manage) where available, or reset the password.
1. Update everything
apt update && apt upgrade -yOn AlmaLinux, Rocky Linux or CentOS Stream, use dnf upgrade -y. Reboot if the kernel was updated: reboot.
2. Create a normal user with sudo
Working as root all the time is risky. Create your own user (replace alex with your name) and give it admin rights:
adduser alex
usermod -aG sudo alexIf the sudo command is missing (some minimal Debian images), install it first as root with apt install sudo.
On AlmaLinux and Rocky Linux, the admin group is called wheel instead of sudo, and you set the password separately with passwd alex. Log in as the new user in a second window and check that sudo whoami prints root.
3. Log in with an SSH key
A key is far harder to guess than a password. On your own computer (PowerShell, macOS or Linux terminal), create a key pair:
ssh-keygen -t ed25519Press Enter to accept the default location and choose a passphrase. Then copy the public key to the server. On macOS or Linux:
ssh-copy-id alex@YOUR-IPOn Windows PowerShell (which has no ssh-copy-id):
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh alex@YOUR-IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"Now ssh alex@YOUR-IP should log you in without the account password.
4. Turn off password and root login
Only do this after step 3 works. Open the SSH config:
sudo nano /etc/ssh/sshd_configSet these lines (remove a leading # if there is one):
PermitRootLogin no
PasswordAuthentication noFiles in /etc/ssh/sshd_config.d/ can override the main file, so check them too:
sudo grep -ri "passwordauthentication\|permitrootlogin" /etc/ssh/sshd_config.d/Change any yes you find there to no. Then test the config and restart SSH:
sudo sshd -t && sudo systemctl restart sshOn AlmaLinux and Rocky Linux the service is called sshd. Test a new login in a second window before closing the first.
5. Turn on a firewall
On Ubuntu and Debian, ufw is the simplest option. Allow SSH first, then enable it:
sudo apt install ufw
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw statusOpen other ports only when you need them, for example sudo ufw allow 80/tcp and sudo ufw allow 443/tcp for a website, or sudo ufw allow 25565/tcp for a Minecraft server. If you changed the SSH port, allow that port instead of OpenSSH. AlmaLinux and Rocky Linux use firewalld (firewall-cmd) instead.
6. Automatic security updates
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgradesAnswer Yes to enable automatic installation of security updates. Ubuntu usually has this installed already; the command makes sure it is on.
7. Block repeated login attempts with fail2ban
sudo apt install fail2ban
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshdfail2ban watches login failures and temporarily bans IPs that keep guessing. If the last command says the sshd jail doesn't exist, or fail2ban won't start (common on Debian 12, which logs to the systemd journal), create /etc/fail2ban/jail.local with:
[sshd]
enabled = true
backend = systemdThen run sudo systemctl restart fail2ban.
Windows VPS
Change the Administrator password to a long, unique one, and never reuse it elsewhere.
Run Windows Update and leave automatic updates on.
Keep Windows Defender Firewall on and only open the ports your apps need.
Don't install software from untrusted sites; it's the most common way Windows servers get infected.
Keep it secure
Keep regular copies of important data outside the VPS.
Install only what you need, and remove software you no longer use.
Turn on two-factor authentication on your billing account too. See How to enable two-factor authentication.
Frequently asked questions
Is my VPS protected against DDoS attacks?
Yes, all Endercloud VPS include DDoS protection. That protects the network, but it doesn't stop password guessing or software bugs, so these steps are still important.
I enabled ufw and now SSH doesn't connect
SSH wasn't allowed before enabling the firewall. Open the web console on your VPS page (billing panel → Servers → Manage) where available, log in, and run sudo ufw allow OpenSSH. Otherwise open a ticket.
I think my VPS was hacked. What should I do?
Copy off the data you need, reinstall the OS, change all passwords, and follow this guide before going online again. See Reinstall the OS.
Was this article helpful?
Related articles
USA (Virginia) VPS are managed inside the billing panel from the Servers page, with Overview, Network, Access, Snapshots, Activity and Settings tabs. ARM plans can't run x86-only software.
Endercloud staff don't read or change your files, and every service has DDoS protection. You keep your account safe with 2FA, sub-users and your own backups.
Put your bot token in a .env file, load it with dotenv (Node.js) or python-dotenv (Python), never commit it to GitHub, and reset it at once if it leaks.
Turn on 2FA under Account → Security in the billing panel and on the Game Panel's account security page, using an authenticator app like Google Authenticator.
