First check the set of rules of your default UFW firewall:
sudo ufw status numbered
Now check the default port of your SSH:
grep -i port /etc/ssh/sshd_config
Now if UFW is not allowing SSH port then please add it in UFW rules:
sudo ufw allow ssh_port_number (type your SSH port default number here)
Now restart your SSH:
sudo systemctl start ssh