I upgraded termux recently.

When I do:

ssh phone

it disconnects after 44 seconds. It disconnects even if there is activity in the session (eg. ping google.com).

If I am active in termux using the phone, then ssh does not disconnect. So it seems Android is killing the ssh connection. tcpdump confirms that and shows a reset packet is sent from the phone killing the connection:

13:30:37.093254 IP > Flags [R.], seq 4542, ack 5622, win 396, options [nop,nop,TS val 3374991 ecr 3768615485], length 0

Before upgrading termux this did not happen. So something happened during the upgrade that caused this to happen.

I have tried both to click acquire wakelock and release wakelock. Neither helped.

I have tried both to click allow and don't allow in Battery Optimization for Termux. Neither helped.

As a workaround I can connect USB. Then Android does not disconnect the ssh-connection. This makes me think the disconnection is deliberate and related to power saving.

How can I make Android not kill the ssh connection?

  • Android isn't killing ssh but Termux app because it doesn't have a background service running. You need to keep Termux in foreground. Or disable Battery Optimization for Termux and Acquire wakelock. When phone is charging over USB, Battery Optimization isn't in effect. Nov 3, 2019 at 14:55

1 Answer 1


Thanks to @IrfanLatif I looked at battery options again.

And my phone was in Power Saving mode. When I disabled that, everything worked - whether Termux is running in the foreground or not.

So the problem was not related to the upgrade of Termux.

You must log in to answer this question.

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