@nikolal I believe you can give termux permission to run in the background, do not battery optimize it and leave the session open. Your remote machine probably has a default timeout for security reasons, if it does you have to turn it off, but i would not recommend it unless you are using key based auth
@nikolal That is probably caused by your device itself lowering power by turning off networking when the screen is off. I am not sure where to change that in Android 9 but you can turn it off so that wifi stays active even when the device is idle.
@mister_monster
I am using key based auth, but I think it may be harder to do that because of android 9 background app sistem. I've enabled other apps to ignore battery optimisation and they still fail to do their tasks as intended. For example I'm using Nextcloud to sync my contacts, calendar etc and it fails to do scheduled task even with battery optimisation off. Thanks for advice anyway