How can I keep ssh (or another command) alive on the terminal app of my Ubuntu phone?

Solution 1:

This post is focusing on the server-side - ignoring the client

Option 1 - screen

I would recommend running those commands via screen.

Some details about the terminal multiplexer screen can be found here.

In short:

  • install screen on server
  • ssh to server
  • start screen and run your command inside the screen session
  • ... imagine disconnect from mobile to server for whatever reason
  • reconnect from mobile to server
  • re-attach to this screen session and enjoy the ongoing process

Option 2 - tmux

tmux is another terminal multiplexer, you can check some details via its man-page.

Option 3 - byobu

byobu is a wrapper that provides various improvements over screen. It uses screen or tmux as a backend. More info on the web page.

Solution 2:

You can use the TweakGeek app. In the Applications menu you will find Terminal. There you can activate a switch called Prevent suspending.

I have tried to connect to SSH from the ubuntu phone's terminal to my laptop, switched app, switched back, and the connection was still alive.

That should do the trick, but as noted in other answers, a mobile phone might not get you the best SSH experience anyway.

Solution 3:

There is a bigger issue waiting for you when you get past that one.

Until earlier this year there used to be support for automatically resuming momentarily dropped ssh connections but it was found to be very insecure and has been removed. This would mean that devices like mobiles that can drop connections or switch routes will be less useful for ssh from now on.

Heres the advisory https://www.qualys.com/2016/01/14/cve-2016-0777-cve-2016-0778/openssh-cve-2016-0777-cve-2016-0778.txt