Start by creating a file

// PMS is the file name$ vim pms
Copy the code

Write in the file, and then save, the file field meaning can be modified as appropriate

#! /usr/bin/expectSet PORT 22 set HOST 192.168.1.8 set USER root set PASSWORD 123456789 spawn SSH -p $PORT $USER@$HOST expect {"yes/no" {send "yes\r"; exp_continue; } "*password:*" { send "$PASSWORD\r" } } interactCopy the code

Sometimes some characters need to escape, some complex passwords will not be recognized, there are complex passwords; If this part is used directly, an error will be reported. .

Next, configure to use this file in iterm2: Click Preferences -> Profiles

  1. Click on the +.
  2. Fill in the name of the
  3. Custom label (optional)
  4. Fixed notation: expect + The full path of the created file

After that, just close this window and we can log in: Click Profiles -> Open Profiles or CMD + O shortcutA new TAB opens, but the TAB name [email protected] I have more servers, it will be difficult to distinguish, so I need to set the default name when opening the new TAB, as follows:When we use these command lines, we often hear the computer beep when we press TAB or Vim, which annoyances me. We can turn it off by setting the following:Sometimes, we will be disconnected and the remote server, then we need to reconnect, may need to be from the Profiles window to open, and this will open a new TAB, and then I have to turn off before disconnected tabs, it’s so trouble, how can the disconnected TAB reconnection? Right-click and restart:But I’m lazy and I want to reconnect faster, so set up a shortcut: open Preferences -> Keys and click NewI set CMD +R shortcut keys

At this point, after a meal of setup, you are ready to enjoy your iterm2.