iptables Allow SSH
Get the full rule set in the correct order, not just one line. Order is what keeps you from locking yourself out.
Your rule set, run in this order
The first rule keeps your current session alive, the second allows local traffic, the third lets SSH in. In normal mode the default policy is switched to DROP last, because setting it earlier cuts you off at once.
Optional safety net before you test
Start a timer that removes the rules after 5 minutes, then run the rule set. If you are still connected and everything works, cancel the timer.
Emergency undo
From the provider's web console or a second session. It removes all INPUT rules, so re-add what you need afterwards.
Keep it after a reboot
Once it works, save with sudo netfilter-persistent save. Details in saving iptables rules. On a cloud server the provider firewall must allow the same port, see Oracle Cloud.
FAQ
Which port does SSH use?
SSH listens on TCP port 22 by default. If you changed it in sshd_config, use that port in the rules.
Why did I get locked out after changing iptables?
Usually the default policy was set to DROP before an SSH allow rule existed, or the allow rule sits after a REJECT rule. Add the allow rules first and test in a second session.
Is it safe to allow SSH only from my IP?
It is stronger, but if your IP changes you lose access. Keep a second way in, such as the provider web console.