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
- Edit the SSH configuration file:
nano /etc/ssh/sshd_config
- Find the line:
PermitRootLogin yes
- Change it to:
PermitRootLogin no
- Save the file and restart SSH:
sudo systemctl restart ssh
- In the same file:
sudo nano /etc/ssh/sshd_config
- Find or add the line:
Port 2222
Note: Replace 2222 with any port you want to use.
- 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
- Install UFW:
sudo apt update
sudo apt install ufw -y
- Allow your new SSH port (e.g., 2222):
sudo ufw allow 2222/tcp
- If you’re still using the default port 22:
sudo ufw allow 22/tcp
- Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing
- Allow HTTP and HTTPS:
sudo ufw allow 80/tcp #http
sudo ufw allow 443/tcp #https
- Enable the firewall:
sudo ufw enable
- Check the status:
sudo ufw status verbose