To install the firewall on debian/ubuntu or other apt based system:
sudo apt install ufw
Next, configure it to allow inbound SSH:
sudo ufw allow OpenSSH
Finally enable the firewall:
sudo ufw enable
If you are planning to run a web server:
sudo ufw allow http
sudo ufw allow https