Please use the following web page for full information on the commands I reference below. UFW Essentials

 

1- sudo ufw enable

2- sudo ufw default deny incoming

3- sudo ufw default allow outgoing

4- sudo ufw default deny routed

 

Is SSH Running on Port 22 (5a) or a Custom Port(5b)?

5a- ufw allow ssh or ufw allow openssh (depending on application reference each allow TCP port 22)

 

5b- sudo cp /etc/ufw/applications.d/openssh-server /etc/ufw/applications.d/customssh

 

6- sudo nano /etc/ufw/applications.d/customssh

change the [OpenSSH] to [customssh]

change the application name to custom ssh server

leave description alone so you know it later references openssh services

change the port number to the port your ssh server uses ex: 1022/tcp

press ctrl + x to exit editing and press y and hit enter to save the file

 

7- sudo ufw allow customssh

 

8- sudo ufw reload

 

for more advanced setting please use the reference at the top of the article