Let’s have a look at how to run a terminal command from your iPhone using Apple Shortcuts. First, we need Shortcuts installed and be working on automation. Let’s add the action: “Run script over SSH” and tap “Show More”.
To enable SSH access on your Mac, we need to open System Settings / Sharing. On the left, we need to enable “Remote Login”. This allows SSH access (read official Apple documentation). Now we need the local network device name. You can find this at the of the Sharing Settings.
We enter this local computer name into “Host” of Shortcuts. Port 22 is correct. In the field “user” you have to put in your Mac username. Suppose you don’t know, open Terminal. There you see your username (matsbauer in my case).
Next step, you can either input the password you use to login into your computer or the SSH key. Let’s look at the SSH key option:
Tap on the SSH Key Authentication type and then the blue “ed12345 Key”. To add the SSH key to your computer, you can email it to you or use AirDrop, Whatsapp, Notes, or the Copy function. I will AirDrop it to my Mac. You will now see a .txt file on your Downloads folder. Open it in TextEdit and copy what's inside (CMD + C). Now go back into the terminal and type:
pbpaste >> ~/.ssh/authorized_keys
And you are good to go!
Now you can add any terminal commands into the field at the bottom. Use && to chain multiple commands.
Have fun creating your Mac automation!