In this article, I show you all the steps needed to secure a web server and improve your security. I recommend doing all of these things on every installation. Also, just because you secure your server doesn’t mean you can neglect it. I highly recommend monitoring it and adjusting security as needed. Monitoring is required for proper security in my opinion.
Install UFW
sudo apt-get update
sudo apt-get install ufw
sudo ufw limit 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Verifysudo ufw status
Do Global blocks
sudo ufw default deny incoming
sudo ufw default allow outgoing
Remote Machine: ssh-keygen -t rsa
Transfer pub ssh key to server
scp ~/.ssh/id_rsa.pub [email protected]:~
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
Copy key and place in authorized_key file in one commandssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Change the following lines in /etc/sshd_config
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
PermitRootLogin no
Enable security features
Change File to mirror below:
order bind,hosts
multi on
nospoof on
sudo apt install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
netstat -tunlp
You will now have completed the basics of a secure web server!