For this task, I secured the server by configuring UFW, hardening SSH, restricting unnecessary ports, and enabling logging. I used the following commands to complete the setup:
1. Configure UFW (Firewall Setup)
----------------------------------------------------------
First, I used these commands to allow SSH access from my IP, enable the firewall, and verify its status:
- sudo ufw allow from {your-ip-address} to any port 22
- sudo ufw enable
- sudo ufw status verbose
2. Harden SSH
--------------------------------------------------------
To improve security, I edited the SSH configuration file using:
- sudo nano /etc/ssh/sshd_config
Inside the file, i changed Port 22 to Port 2222
Changed PermitRootLogin yes to PermitRootLogin no
Then I used these commands to allow the new port and apply the changes:
- sudo ufw allow 2222
- sudo systemctl reload ssh
3. Restrict & Manage Ports
--------------------------------------------------------
To open HTTPS and manage firewall rules, I used:
- sudo ufw allow 443
- sudo ufw status numbered
- sudo ufw delete <rule-number>
4. Enable Logging & Monitor Activity
--------------------------------------------------------
To enable logging and monitor suspicious activity, I used:
- sudo ufw logging on
- sudo tail -f /var/log/ufw.log
- sudo tail -f /var/log/auth.log