Keep Termux Always Online: Prevent Session Closing
To keep Termux always online and prevent the session from closing easily, you can follow these steps:\n\n1. Use a reliable terminal emulator app: Install a terminal emulator app that provides a stable and reliable connection. Some popular options include Termux:API, JuiceSSH, or ConnectBot.\n\n2. Use a persistent connection method: To prevent disconnections due to network issues or inactivity, you can establish a persistent connection using tools like tmux or screen. These tools allow you to create multiple virtual terminals within a single session.\n\n - Install tmux: Open Termux and run the following command:\n \n pkg install tmux\n \n\n - Create a new tmux session: To create a new tmux session, run the command:\n \n tmux new-session -s session_name\n \n\n - Detach from the session: To detach from the session without closing it, press Ctrl+b followed by d. \n\n - Reattach to the session: Whenever you want to reconnect to the session, open Termux and run the command:\n \n tmux attach-session -t session_name\n \n\n3. Utilize Termux:Boot (optional): If you want to automatically start Termux on boot, you can install the Termux:Boot package. This will allow Termux to launch in the background every time your device starts up.\n\n - Install Termux:Boot: Open Termux and run the following command:\n \n pkg install termux-boot\n \n\n - Configure Termux:Boot: After installation, run the following command to set up the Termux:Boot:\n \n termux-boot\n \n\n This will create a ~/.termux/boot/ directory where you can add scripts that will be executed on boot.\n\n For example, you can create a script named start_tmux.sh in this directory and add the following content:\n \n #!/data/data/com.termux/files/usr/bin/sh\n tmux new-session -d -s session_name\n \n\n Save the script and make it executable by running the command:\n \n chmod +x ~/.termux/boot/start_tmux.sh\n \n\n4. Disable battery optimization (optional): Certain devices aggressively optimize battery usage, which can lead to session disconnections. To prevent this, you can disable battery optimization for Termux:\n\n - Open your device's Settings.\n - Go to Battery or Battery Optimization.\n - Find Termux in the list of apps.\n - Set it to "Don't optimize" or "Not optimized".\n\nBy following these steps, you should be able to keep Termux always online and prevent the session from closing easily.
原文地址: https://www.cveoy.top/t/topic/pCF1 著作权归作者所有。请勿转载和采集!