If you don't have access to the router to do port forwarding, BUT you do have a ssh access to some server that is outside your local network and is accessible from the Internet, you can use that server as a "middleman" to access your PC.
First, you need to establish a ssh tunnel between your PC and that server, by using on your PC a command like:
ssh -R portnumber:localhost:22 [email protected]
where username is your username at external.server and portnumber is any unused port number on that server that you will choose (for example, 9922). "localhost" is literally the word localhost
.
You should leave this connection active permanently. You have to ensure somehow that this connection is kept up all the time and does not disconnect (you can for example write some script that checks periodically if the connection is active and reconnects if it's not).
As a next step, if the ssh server on external.server is configured to accept outside connections to tunneled ports (this requires the option GatewayPorts yes
to be present in /etc/ssh/sshd_config
file on external.server; the default is no
), you can connect directly to your PC from outside by connecting to portnumber on external.server, like below:
ssh -p portnumber [email protected]
where localuser is your username on your PC (not the external server!)
However, if the external server is not configured to accept outside connections to tunneled ports (which is far more common as this is the default), you need to make the connection in two steps.
First, log in to the external server as you would normally:
ssh [email protected]
Once logged in to external.server, type the following command (on the server):
ssh -p portnumber localuser@localhost
where localuser is your username on your PC, and "localhost" is literally localhost
. You should be logged in to your PC now.