i am stuck with a problem for a week now. I am trying to access my computer by ssh from my ios devices like iphone or ipad but without being on the same network. Everything is doing great on the same network using the ssh command. I have heard about port forwarding, public ip adress or modem configuration but i don't actually understand the different steps. How can i access my laptop from external network especially ios devices ( if there is a difference ) ?
2 Answers
Indeed you need to set up a port forwarding.
The first question to ask yourself is whether your router (which allows Internet access) allows port forwarding? To do this, connect to the administration console of this one.
If yes, do :
The machine on which you want to connect in ssh must be in fixed IP ex: 192.168.1.10 It can be configured in your router admin panel.
Know your public IP address
In the admin panel of your router, create a new setting and redirect port 22 TCP (internal and external port) to the fixed IP ex: 192.168.1.10
Connect to port 22 of your public IP.
I hope I helped you.
See you soon.
The Secure Shell protocol requires both endpoints to have an IP address in the same network. If the client belongs to a private network, the server must have an address in that network; if the client belongs to the global network, your server must be exposed via a public IP address in order to be accessible. That is how the protocol works, regardless of any hardware vendors, operating systems or network providers, and there is no way around this.
If your server device (your computer in this case) does not have a public IP address, the simplest solution would probably be setting up the router that provides the network for your server to forward the port 22 of your server to a port (preferably other than 22) on its public interface. This is highly vendor specific, so, given you have control over the router, you should check its documentation on how to configure it for this.
The reasons for picking an external port on router other than 22 are not vendor specific, however: one is you may not want to disable SSH access to the router itself (which may or may not apply in your case), another is that port 22 is obviously a well known servce port that is a very common target for security attacks, and you may not want to expose your computer to those.
A more secure alternative to manually configuring your router to permanently expose the SSH port of your server to the Internet, would be using your the SSH server on your router to forward the SSH connection to your server. If your client is running OpenSSH v7.3 or later, there is a simple command line option for this, -J
:
ssh [user@]host -J [user@]jumphost[:port]
e.g. (assuming the IP of the server is 192.168.1.2 in the network behind the router, and myrouter
resolves to the public IP of the router, and there's an account for the connecting user in both devices)
ssh 192.168.1.2 -J myrouter
Read up the linked article for more ways to accomplish this.