Use iTerm2 to build a macOS ssh artifact

In daily work, it is often necessary to connect to a remote server through ssh, and it will be troublesome to enter a password every time you connect.
On the Windows system, I am used to using xshell to manage connections, which is very convenient.
On the macOS system, there is no xshell, and among some tools similar to xshell, the easy-to-use tools need to be charged, and the free ones are not easy to use, so I decided to use iTerm2 to create a useful ssh artifact to improve daily work efficiency.
Without further ado, let's go straight to the dry goods.

Use iTerm2 to create an ssh artifact, mainly through the Profiles function, each Profile corresponds to an ssh connection, and then open the Profile to connect to the remote server.
For details on how to configure Profile, see below.

Configure Profiles

1. Create a new Profile

Open iTerm2, navigate to iTerm2 > Settings, and open the configuration management page:
insert image description here
insert image description here

Switch to the Profiles management page on the configuration management page:

insert image description here

Click the "+" button to create a new Profile:

insert image description here

The newly created Profile is as shown below:
insert image description here

You can also copy a new Profile from an existing Profile, which can reduce the configuration. The copying method is as follows:
insert image description here

There are more functions, so I won’t go into details here.

2. Configure ssh connection

2.1. Configure basic information

Configure ssh connection information, as shown in the figure:
insert image description here

The Name area is the configuration profile name.
Select the Command option in the Command area and configure the ssh connection command. The password configuration will be described in detail below.
The Tags area is tags, and multi-level tags are separated by "/". When there are many Profiles, you can locate the target Profile faster by filtering by tags.
Click the Tags button to view the tag tree:
insert image description here

2.2. Configure password

After configuring the ssh connection, every time you open the profile, you will directly execute the ssh command to connect to the remote server, and then require manual input of the password.
If you want to autofill passwords, you need to use Triggers. Triggers will monitor the output text of the terminal seesion, and if the text matches a regular expression, the action corresponding to the regular expression will be executed.
Configure the regular expression in Triggers to match the prompt text of the input password, and then trigger the input of the password text or pop up the password manager to realize the function of automatically filling the password or selecting a password from the password manager.
Continue to edit Profile and open the advanced configuration:
insert image description here

Edit Triggers:
insert image description here

Add a rule to automatically enter the password:
insert image description here

The regular expression "(P|p)ass(word|wd):" of the above rule can match the prompt text for entering the password, and then trigger the action "Send Text", which will send the text configured in Paramters to the terminal session In , the function of automatically filling passwords is realized.
Send Text automatically enters the password, you need to add a carriage return (\r) or line feed (\n) at the end of the password text, so that you can directly connect to the remote service, otherwise you need to manually press the Enter key to connect to the remote server .

You can also choose to trigger the password manager, manually select the account password, and then connect to the remote server. The rule configuration is as follows:
insert image description here

The regular expression "(P|p)ass(word|wd):" of the above rule can match the prompt text for entering the password, and then trigger the action "Open Password Manager". After the password manager is opened, the default selection is Account password configured in Parameters.
The trigger effect is as follows:
insert image description here

You can see the account password selected by default. Click the "Enter Password" button to send the password to the terminal session and connect to the remote server.
The default account password configured in the trigger rule needs to be created in the password manager in advance.
The creation method is as follows.
Open the password manager:
insert image description here

Click the "+" button to edit:
insert image description here

Use Profile

Just click the target Profile directly, as shown in the figure:
insert image description here

Reference:
https://blog.csdn.net/ClownG/article/details/107849908
https://blog.josephziegler.com/2022/03/20/iterm2-password-trigger.html

Guess you like

Origin blog.csdn.net/xwd127429/article/details/131126690