This article completely copied, pure do records, the original links: zhuanlan.zhihu.com/p/69379306

The official website is as follows:

A trigger is an action that is performed when text matching some regular expression is received in a terminal session.

Iterm2 can be set to perform operations that match a specific output from a terminal. For those familiar with Expect, this is the way the software itself supports automatic logins.

Without further ado, go to Settings.

First click on Profiles->Open Profiles, MAC shortcut: Command +O

Select the server you want to log in to and click Edit Profiles

Command Specifies your SSH login IP and user name, or port if not 22

Then click Advanced, find Trriggers, and click Edit

In the Regular expression field, enter the Regular expression you want to match. In this field, enter the password as prompted by “password”. If your server prompts “passwd” for the password, you will need to match the Regular expression. Select Send Text in Action, fill in your password in Parameters, and add a \ R character at the end. \r is enter, which is equivalent to entering your password and pressing enter. Finally, check the box for Instant.

At this point, you double click your profile, you can automatically log in.