iOS backgrounding
This is the most important platform page for iPhone and iPad users. iOS suspends apps about 30 seconds after they go to the background, and their network connections go with them. Every SSH session, port forward and SFTP transfer in ZestSSH stops when that happens.
What happens
Section titled “What happens”When you switch to another app or lock the screen:
- iOS suspends ZestSSH after about 30 seconds.
- Your SSH connections are closed.
- Port forwards and SFTP transfers in progress stop.
- Unsaved work in an editor on the server (vim, nano) can be lost, unless the server keeps the session (see tmux below).
Why it happens
Section titled “Why it happens”iOS limits what apps can do in the background to save battery. It has no background mode for keeping an SSH connection open. The only background mode ZestSSH declares is background fetch, which does not keep a connection alive.
ZestSSH does not use workarounds such as playing silent audio or asking for your location to stay awake. They drain the battery and go against the App Store’s rules.
What ZestSSH does
Section titled “What ZestSSH does”Tells you what dropped
Section titled “Tells you what dropped”When you come back to ZestSSH and a session that was connected has dropped, a notice shows at the top for 5 seconds:
- With Auto reconnect on: “Connecting N sessions again…” (or “Connecting a session again…”).
- With Auto reconnect off: “N sessions were disconnected while ZestSSH was in the background.”
Tap Why? on the notice to open the in-app page iOS & SSH connections, which explains the same limits as this page.
Connects again by itself
Section titled “Connects again by itself”Auto reconnect is on unless you turn it off. In a session, tap Terminal settings (the gear in the session’s toolbar) to find the Auto reconnect switch.
While it is on, a dropped session is connected again by itself:
- Up to 10 tries, waiting 2, 4, 8 and 16 seconds, then 30 seconds between each later try.
- If every try fails, the session stays dropped and says “Auto-reconnect failed after 10 attempts”. Tap Reconnect to try again. The session’s tab stays where it was.
- After a host key problem, ZestSSH does not connect again by itself. You decide what to do.
Notices a quiet connection
Section titled “Notices a quiet connection”When three keep-alives in a row get no answer and nothing else comes from the host, the session is shown as lost. With the usual keep-alive of 30 seconds, that takes a minute and a half to two minutes. Without this, a session could look connected after iOS or the network had already cut it.
Starts your forwards again
Section titled “Starts your forwards again”A port forward with Auto-activate on connect turned on starts again when its session reconnects. The first time you open port forwarding on an iPhone or iPad, ZestSSH tells you about these limits; Learn more opens the iOS & SSH connections page. See Port forwarding.
What you can do
Section titled “What you can do”Use tmux or GNU screen
Section titled “Use tmux or GNU screen”A terminal multiplexer running on the server keeps your session alive whatever happens to the SSH connection.
$ tmux new -s workAfter ZestSSH reconnects, attach to it again:
$ tmux attach -t workGNU screen works the same way:
$ screen -S work$ screen -r work # attach again after reconnectingTo attach by itself every time you connect, put the command in the host’s Startup command (optional) field. See tmux auto-attach.
Mosh keeps the session
Section titled “Mosh keeps the session”From 4.0 ZestSSH has Mosh built in on iPhone and iPad. A Mosh session lives through iOS suspending ZestSSH and through a change of network: when you come back, it picks up where it was, with no new sign-in. The host needs mosh-server and UDP ports 60000 to 61000 open. For a history that survives anything, run tmux or screen inside the Mosh session. See Mosh. (Eternal Terminal is on computers only.)
Frequently asked questions
Section titled “Frequently asked questions”Can ZestSSH keep connections alive in the background on iOS? No. iOS gives apps no background mode for SSH connections.
Why can Android keep connections in the background? On Android, ZestSSH runs a foreground service with a notification while sessions are open, and Android lets that keep running. iOS has nothing like it for network connections. See Android background automation.
My session dropped and I lost unsaved work. What can I do? Use tmux or screen on the server from now on. They keep your editor running on the server when the connection drops. Some editors (vim) also keep swap files you can recover from.