How to access home ssh server from outside via the Internet?

I am running ubuntu server 20.04 and out of the blue I am getting operation timeout. I was wondering how can I troubleshoot the issue.

I am using ufw and the connection port is open. so when I use sudo ufw status , it shows me that the port is accessible.

When I run systemctl status sshd I get that the process is active and that sshd is listening to 0.0.0.0 port xx and :: port xx

I can log on to the machine using my user, so the credentials are not an issue here. I am also able to ping the server from another machine and the ping is working well.

Edit: I am able to connect to the server on the intranet, but not from outside. Is there a way for ssh to be blocked from the internet and not from the intranet?


Port setup

See the Wikipedia on Port Forwarding to learn more about why you need it.

ssh uses port 22 by default. I will assume you have not changed that. If you changed that port, then you will need to make changes in the instructions below accordingly.

Router setup

Make sure port 22 is forwarded to the Ubuntu server's internal IP address in the home router. This will allow anyone from outside the home LAN use ssh to connect to the home computers.

The instructions are router specific and beyond the scope of this answer as it has nothing to do with Ubuntu.

Some routers allow specifying both incoming port (from the Internet) as well as outgoing port (to the internal IP address of the LAN for the Ubuntu server). In that case, you may want to use a different port, say 2200, when you connect from the outside, and setup your router accordingly:

enter image description here

The picture above is just an example. The settings in your router may look different.

If you have changed the default port in /etc/ssh/sshd_config then you will need to set the internal port above to that port, instead of port 22.

To learn how to setup ssh to work within the home lAN, see Connect two computers with SSH in a home LAN

Here is another port forwarding: how to guide for reference.

Hope this helps