Termux, sshd connection problems via WLAN

What I want to do:
I often have to transfer files from my PC to my smartphone. With my old smartphone, I used SSH scp to quickly send files without the need to plug in a USB cable.

With my new /e/ Fairphone 3, I figured out the following way:

  1. install Termux from F-Droid repository
  2. install openssh in Termux environment
  3. start the SSH Server via sshd (see Termux OpenSSH Tutorial)
  4. connect from my PC via ssh -p 8022 <SMARTPHONE_IP_ADDRESS>

The problem:
This seems to work in some cases. But in about 60% of all connection attempts, the connection fails with “Connection timed out” shown on my PC.

Even if I repeat step 4 in 10 different PC Linux terminals within 5 Minutes, I get some succeeding connections and many “timed outs”.

In case of “connection time out” I can’t see any activity in SSH daemon’s log, started with sshd -d.

Testing different device:
I tried the same setup with a friends “Google Android smartphone” (same Linux PC, same WLAN, same Termux app): SSH-Connection works 100%

So I guess it is a problem with my “/e/ Fairphone 3”.

What could be wrong, but is not:
I am sitting direct next to the WLAN box, so I have 100% WiFi signal strength. My smartphone battery is at 60% and I enabled “unrestricted data usage” for the Termux app.
I think, the WiFi connection is ok: Transferring 1.3 GByte from my PC to my eFP3 took 113 seconds which is about 11 MByte/s.

Any ideas, what to test next?

Can you change the listening port, to something like 22222 ?

Thank you for the idea! I tried port 31997 (sshd -p 31997), but I get the same experience as with the default port 8022.

If you can’t see any entries in sshd’s log, something is preventing connection to reach it.
Did you install any firewall, tracker blocker, … ?

Also, I’ll try to find something like “netstat” on Android, to check if sshd is correctly listening on asked TCP port.

My /e/FP3 is not rooted and I haven’t installed any additional firewall or tracker blocker.

My problem is: When try to make 5 SSH connections, I get something like:

  1. connection successful (connected within 5 seconds)
  2. connection successful (connected within 2 seconds)
  3. connection timed out (more than 30 seconds to connect)
  4. connection successful (but took 10 seconds to connect)
  5. connection timed out (more than 30 seconds to connect)

Maybe that something in my eFP3 is not listening all the time. Is there some process in Android, which puts the Termux App asleep?

Tested on my Xiaomi santoni running latest /e/ Pie, I couldn’t reproduce your problem :frowning:

About battery optimization, you can try this setting :

You can also try continuously pinging from another Termux session (i.e. your gateway, PC, AP).

Thank you @smu44 for your tests.

I had those battery settings already.

Continuosly pinging is a good idea, but did not help.

I also tried switching Settings > Battery > Battery saver and performance > Performance profile from “Balanced” to “Performance”. But this did not help either.

One more thing you can try, as an attempt to identify the problem, is to bypass the WLAN layer using adb : https://glow.li/posts/access-termux-via-usb/

Thanks. Changing port worked for me. SSH is now working in on my Android device.