How to Automate Commands When You Connect: Login Scripts for SSH on iPhone

TL;DR

Login scripts (Premium) wait for an "expect" text and then type the matching "send" text, in order, after the shell connects. Leave "expect" empty to send immediately. Steps are stored with the server record, so don't put secrets in them.

The problem

Every time you connect to a particular server you do the same dance: sudo su -, cd /srv/app, source .env, maybe attach to tmux. On a phone keyboard that is thirty seconds of typing before you do any real work, and it’s the part you’re most likely to mistype.

What login scripts do

A login script is a list of steps run after the interactive shell connects. Each step has:

  • expect: text to wait for (such as a prompt).
  • send: text to type once that appears.

If expect is empty, the step sends immediately, which is right for something like sudo su -.

Examples

Goalexpectsend
Become root(empty)sudo su -
Go to the app folder#cd /srv/app
Attach to tmux(empty)`tmux attach -t deploy

Set one up

  1. Edit the server → Login Scripts → New step.
  2. Fill in expect and send. Add more steps in order.
  3. Save and connect. The steps run once the shell is ready.

Cautions

  • Don’t store passwords here. Login scripts live in the server’s stored data, not the Keychain, and they can be included when iCloud sync is on. Prefer SSH keys and passwordless sudo rules for the commands you need.
  • Wrong expect text means a stuck script. If a prompt differs from what you wrote, the step will wait. Test it.
  • Automating privilege escalation is convenient, and a mistake runs as root. Keep scripts short and obvious.
  • Premium.

FAQ

How do the steps work? For each step the app waits for the “expect” text to appear, then types the “send” text. With an empty expect, it sends straight away.

Should I put a password in a step? No. Steps are stored with the server record, not in the Keychain, and can sync with iCloud sync. Use keys and sudo rules instead.

Is it free? Login scripts are a Premium feature.