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:
Switch to the Profiles management page on the configuration management page:
Click the "+" button to create a new Profile:
The newly created Profile is as shown below:
You can also copy a new Profile from an existing Profile, which can reduce the configuration. The copying method is as follows:
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:
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:
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:
Edit Triggers:
Add a rule to automatically enter the password:
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:
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:
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:
Click the "+" button to edit:
Use Profile
Just click the target Profile directly, as shown in the figure:
Reference:
https://blog.csdn.net/ClownG/article/details/107849908
https://blog.josephziegler.com/2022/03/20/iterm2-password-trigger.html