Remote port forwarding on AWS EC2 does not open ports

Long story short, but by default SSH daemon does not open ports to the internets when you make remote port forwarding, e.g. allows to connect to ports from localhost only.
That’s smart, of course.

To allow connecting from the internets to your new ports you need to add changes to sshd config /etc/ssh/sshd_config:

Add there following line:

GatewayPorts yes

Now when you do

ssh -v -R 8080:localhost:4000 [email protected] -i ~/.ssh/key.pem

You will be able to make a request from outside 🙂