First, ufw needs to be enabled. From a terminal prompt enter:
sudo ufw enable
To open a port (SSH in this example):
sudo ufw allow 22
Similarly, to close an opened port:
sudo ufw deny 22
To remove a rule, use delete followed by the rule:
sudo ufw delete allow 22
Uncomplicated Firewall (ufw) on Ubuntu