Skip to content

Automating SSH with Tasker

ZestSSH’s automation lets other apps run SSH commands on your saved hosts. On Android, Tasker is the most flexible way to use it: run a deploy at a set time, start a backup when you leave home, or check a server every hour.

This guide walks through the setup, then gives examples you can copy. Everything here runs through Android intents (Tasker’s System > Send Intent action), because an intent runs without asking you, which a timed or triggered task needs. A zestssh:// link would stop at Run this from a link? until you tap Run.

  • Squeezed (automation needs it)
  • Tasker on your Android device
  • At least one saved host in ZestSSH that you can connect to with a saved key or password

In ZestSSH, open More > Automation and turn on External automation. Confirm Enable external automation? with Enable.

  1. On the same page, tap API keys, then + (or Create API key when you have none).
  2. Give it a Label, for example “Tasker”.
  3. Pick an Expiration: Never, 30 days, 60 days, 90 days, or Custom.
  4. Tap Create. In Save your API key, copy the key with Copy to clipboard, tick I’ve copied this key somewhere safe, and tap Done. The clipboard is cleared 45 seconds later.

The key is 48 characters long. This is the only time it is shown: ZestSSH keeps only a hash of it, so paste it into Tasker (or your password manager) now. If you lose it, make a new key and revoke the old one.

Security notes:

  • Keys are checked in constant time, so how long a check takes says nothing about the key.
  • After 5 failed attempts in a row, unknown keys are locked out for 1 minute; after 10, for 5 minutes; after 15 or more, for 30 minutes. A valid key still works during a lockout, and clears it.
  • Make a key per Tasker setup, so you can revoke one without breaking the others.

See API authentication for the details.

Step 3: Allow your keys for unattended runs

Section titled “Step 3: Allow your keys for unattended runs”

A run from Tasker has nobody there to answer a question, so ZestSSH signs in only with SSH keys you allowed for that:

  1. Open Manage > Keys.
  2. Open the key the host signs in with (and the keys of its jump hosts, if it has any).
  3. Turn on Allow unattended runs under Unattended runs, and confirm.

A run that would need a key not allowed, a code, or a password that is not saved is refused.

A run with nobody there trusts only host keys this device already trusts. Open a session to each host once, check its key and accept it. A host whose key changed later is refused until you connect yourself and see what changed.

Open Tasker, go to Tasks, and create a new task. Add the action System > Send Intent and set:

  • Action: com.affluentlabs.zestssh.EXECUTE
  • Package: com.affluentlabs.zestssh
  • Target: Activity
  • Extra: key:YOUR_API_KEY
  • Extra: connection_id:web-01
  • Extra: command:uptime
  • Extra: timeout:30

Put each extra in an Extra field of its own, as name:value. Setting the package means no other app is offered the intent and its key.

Run the task. The run appears in More > Automation > Automation history, with its output.

ZestSSH can build the intent for you: More > Automation > Automation wizard walks through the action, the host, the command and the filters, and ends with a Tasker intent card to copy. The card holds YOUR_KEY where your key goes, unless you make a new key there with Make a new key for this: then it holds that key until you close the wizard.

connection_id is matched first against a host’s ID, then against its name in any letter case. There is no partial match: connection_id:prod never matches “prod-staging”. The run uses the hosts of your personal space, whatever space is on screen, and signs in as a session to the host would, through its jump hosts and as your current network has the host.

ZestSSH hands stdout and exit_code back only to an app that started it for a result. To act on a result whatever starts the task, use a webhook callback (below), or read the run in Automation history.

EXECUTE and BATCH take filters as extras:

Extra Effect
grep:pattern Keeps only lines that match the pattern (a regular expression, any letter case)
head:N Keeps only the first N lines
tail:N Keeps only the last N lines

They apply in that order: grep, then head, then tail.

Add a callback extra with an HTTPS address to an EXECUTE or BATCH intent. When the command ends, ZestSSH sends a POST with a JSON body holding connection, command, stdout, stderr, exit_code, elapsed_ms and timestamp:

Action: System > Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:web-01
Extra: command:uptime
Extra: callback:https://hooks.example.com/results

Only https:// addresses are used; localhost, private and link-local addresses are refused, and redirects are not followed. The POST is sent once. See Webhook callback.

Profile: a time trigger at 02:00 every day.

Action: System > Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:nas-01
Extra: command:/opt/backup/nightly.sh
Extra: timeout:300
Extra: callback:https://hooks.example.com/results

300 seconds is the longest a run waits. For a backup that takes longer, start it in the background on the server (for example with nohup) and let it report by itself.

Example 2: deploy when a notification arrives

Section titled “Example 2: deploy when a notification arrives”

Profile: Tasker’s notification event for your Git hosting app.

Action: System > Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:prod-01
Extra: command:cd /var/www/app && git pull origin main && docker compose up -d --build
Extra: timeout:120

Chain commands with && so the deploy stops if git pull fails.

Profile: a time trigger every hour.

Action: System > Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:web-01
Extra: command:uptime && free -m && df -h /
Extra: timeout:15
Extra: callback:https://hooks.example.com/results

If you have a saved snippet named restart-nginx:

Action: System > Send Intent
Action: com.affluentlabs.zestssh.SNIPPET
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:prod-01
Extra: snippet_name:restart-nginx

The snippet is found by its name in any letter case. To pass values, add a var_NAME extra for each {{NAME}} in the snippet’s command. For a snippet with git checkout {{branch}}, the extra var_branch:develop runs git checkout 'develop': each value is shell-escaped. The snippet editor’s own ${NAME} variables are filled the same way: var_NAME fills ${NAME} (and ${NAME:-default}) too.

A snippet run waits at most 30 seconds and takes no filters or callback.

Action: System > Send Intent
Action: com.affluentlabs.zestssh.BATCH
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connections:web-01,web-02,web-03
Extra: command:uptime
Extra: parallel:true
Extra: timeout:60

connections is a comma-separated list of host names or IDs (connection_ids is read too). With parallel:true (the default) at most 4 hosts run at once; with parallel:false they run one after another, in the order given. A batch takes at most 25 hosts.

The combined output has a section for each host:

=== web-01 (exit=0) ===
14:23:01 up 42 days, 3:12, 1 user, load average: 0.08, 0.03, 0.01
=== web-02 (exit=0) ===
14:23:01 up 10 days, 6:40, 0 users, load average: 0.15, 0.10, 0.09
=== web-03 (exit=1) ===
STDERR: error message

Workflows are multi-step sequences you build in ZestSSH (More > Automation > Workflows). Run one by name or ID:

Action: System > Send Intent
Action: com.affluentlabs.zestssh.WORKFLOW
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: workflow_name:nightly-maintenance

Or use workflow_id with the workflow’s ID. A workflow runs its steps in order, and each step’s failure can Abort, Continue, or Go to another step. A key limited to one host cannot run a workflow, and a workflow switched off in the workflow list is not started. A workflow has no webhook; a Notify step in it shows a notification on the phone instead.

To open a lasting session, so its port forwards set to start with the connection come up, use the OPEN action:

Action: System > Send Intent
Action: com.affluentlabs.zestssh.OPEN
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:office-gateway

OPEN waits up to timeout seconds (default 30) for the session to connect.

From a computer with ADB, send the intent itself:

Terminal window
adb shell am start -a com.affluentlabs.zestssh.EXECUTE \
-n com.affluentlabs.zestssh/.MainActivity \
--es key YOUR_API_KEY --es connection_id web-01 --es command uptime

The wizard’s ADB command opens a zestssh:// link instead, which asks Run this from a link? first, so it does not test what Tasker does.

  • One API key per Tasker setup. Revoke one without breaking others.
  • Pick a timeout that fits. The default is 30 seconds, the range 1 to 300.
  • Keep long commands in snippets. Change them in one place.
  • Try commands yourself first in a ZestSSH terminal.
  • Keep your API key private. A Tasker task holds the key as you typed it: do not share or publish one with a real key.
  • Check the automation history (More > Automation > Automation history, up to 500 runs) when a task does not do what you expect. When ZestSSH refuses a request, it also shows a notice saying why.