I have two phones A and B which use Mobile Data. I would like to connect from phone A to phone B, the latter has an SSH server running on port 8022. The central SSH server is running on AWS and has an Elastic IP. Phone A can connect to AWS Server directly at port 22, so can phone B.

AWS Server configuration:

GatewayPorts yes
TCP forward yes
Password Authentication Yes 

Further, I have forwarded port 9099 on the AWS SSH server to local port 8022 on phone B:

~$ ssh -NR 9099:localhost:8022 user@Remoteip 

By running netstat -tpln on the AWS SSH server, I can see that 9099 is in listening mode.

But when I ssh from phone A into the AWS server at port 9099, it says timed out.


1 Answer 1


What I have understood from your question:

You have two phones A and B, which are connected to internet through Mobile Data. Phone B has a SSH server running, listening on port 8022. You want to login from phone A to phone B, but since the later doesn't have a public IP, you want to create a reverse SSH tunnel from phone B to another SSH server running on AWS cloud, listening on port 22. In this way you want that all traffic received on port 9099 on AWS SSH server should be forwarded to port 8022 on phone B, so that phone A can access it on internet.

If I understood correctly, the simplest thing you have to do is:

  • On AWS run a SSH server, which is listening on port 22. Since you are able to login to this server from both phones A and B, I think you have done it correctly. Let's say your login user here is server_user and IP address is server_ip.

    You need two additional keywords in /etc/ssh/sshd_config, should look like this exactly (no extra spaces):

    # /etc/ssh/sshd_config
    AllowTcpForwarding yes
    GatewayPorts yes

    After changing configuration, don't forget to restart server.

    • First parameter ensures that port forwarding is allowed i.e. you'll be able to create tunnel.
    • Second parameter ensures that the reverse tunnel will listen on all network interfaces, and not only the local (loopback) interface on AWS server.
  • On phone B run a SSH server, which is listening on port 8022, let's say your login userame is phone_user (Termux's SSHD requires no username).

    Do test if you can login to this server. For instance create hotspot on phone A or B or connect both to some third WiFi network. Now login from phone A to phone B. If it doesn't work, troubleshoot the problem, most likely with password / key authentication.

  • On phone B create a reverse tunnel i.e. forward AWS SSH server's port 9099 to phone B's (local) port 8022:

    ~$ ssh -NR 9099:localhost:8022 server_user@server_ip

    This can be done on Termux or use some GUI app like ConnectBot.

    To test if the the tunnel works correctly, on AWS server:

    ~$ ssh phone_user@localhost -p 9099

    It should login you to phone B.

  • On phone A, login to phone B through AWS SSH server:

    ~$ ssh phone_user@server_ip -p 9099

If it doesn't work, repeat the steps.


  • Id like to confirm that if i need to make http requests on Phone B via Phone A,do i need to have a server or a Client should get the job done Commented Jul 16, 2019 at 19:26
  • @EhtizadZashkiyor sorry couldn't understand what you mean by http requests. Do you want to host a web server on phone B? Commented Jul 16, 2019 at 19:38
  • Basically I would like to connect Phone A to Phone B and access the Internet through phone B .So do I need to have a server on Phone B to do this or a client on phone B can do the same ? Commented Jul 16, 2019 at 19:41
  • @EhtizadZashkiyor You can't connect a client to client. At least one end should be a server. Commented Jul 16, 2019 at 19:46
  • Ok.Let me configure the server and update about this . Commented Jul 16, 2019 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .