VPS servers


Basic server configuration for VPS - Debian/Ubuntu

Creating a New User

adduser username

Add the user to the sudo group (so they can run administrator commands):

usermod -aG sudo username

Disabling Root Login via SSH and changing the SSH Port

  1. Edit the SSH configuration file:
nano /etc/ssh/sshd_config
  1. Find the line:
PermitRootLogin yes
  1. Change it to:
PermitRootLogin no
  1. Save the file and restart SSH:
sudo systemctl restart ssh
  1. In the same file:
sudo nano /etc/ssh/sshd_config
  1. Find or add the line:
Port 2222

Note: Replace 2222 with any port you want to use.

  1. Restart SSH:
sudo systemctl restart ssh

Note: After changing the port, connect using:

ssh -p 2222 username@server_ip

Installing UFW and basic firewall configuration

  1. Install UFW:
sudo apt update
sudo apt install ufw -y
  1. Allow your new SSH port (e.g., 2222):
sudo ufw allow 2222/tcp
  1. If you’re still using the default port 22:
sudo ufw allow 22/tcp
  1. Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing
  1. Allow HTTP and HTTPS:
sudo ufw allow 80/tcp #http
sudo ufw allow 443/tcp #https
  1. Enable the firewall:
sudo ufw enable
  1. Check the status:
sudo ufw status verbose