Use iterm2 to configure the correct posture of ssh on Mac!

Preface

There are many tools for connecting to remote servers, and I have basically tossed them. In summary, the two non-xshell and SecureCRT with the best experience and the largest number of users are none other than xshell and SecureCRT. Look at the comparison chart below:

tool Supported platforms Session replication Is there a free version Genuine price
Xshell Windows stand by Have ¥988+
SecureCRT Windows、Mac、Linux stand by no ¥900+

I believe that most people are used to it but "can't afford it". Although there are many cracked versions on the Internet, they always feel that it is not practical (will this thing have a Trojan horse? Is there a backdoor? Why is my password leaked? do?).

alternative plan

For students who use Mac, the simpler alternative is to use iterm2 .
At present, the most introduced online is the automatic login realized in the following two ways:

  • shell脚本 + expect + iterm2触发器
  • shell脚本 + sshpass

Both of these methods seem very lame, do you have to use shell scripts? kao.
Besides, the password is also exposed in the shell script in plain text. Isn't it necessary to add a password?
Friends who are not sensitive to passwords and shells can find out how to achieve it. It is not recommended here.

The method introduced here is to 纯使用iterm2achieve, you can do not expose the plaintext password.
The disadvantage is that it is not automatic login, and you need to use shortcut keys to call up the password manager.
what? Don’t log in automatically? Have to learn another shortcut? Then you talk about wool!

I don't care, I just don't want to use shell scripts, I just don't want the password to be written in the file in plaintext.
I don't care, I just don't want to use shell scripts, I just don't want the password to be written in the file in plaintext.
I don't care, I just don't want to use shell scripts, I just don't want the password to be written in the file in plaintext.

Let's have a demo first

  1. cmd + o Open the server list, select the machine to log in with the arrow keys, press Enter, and prompt for the password;
  2. option + cmd + fOpen the password manager, select the password with the arrow keys, and press Enter to log in;
  3. If you repeat step 1 at this time, you do not need to enter a password for copying with the ssh session.
    ssh-login-demo

Start configuration

Add server

Click iterm2—>Preferences—>Profiles, configure a new profile as shown
Add profile

Configure password manager

Click iterm2-> Window-> Password Manager, a password according to the configuration shown, arranged after the press ESCbutton to close the window
Configure password

Configure SSH session replication and session retention

Students who have used SecureCRT and Xshell know that there is a session copy function. In fact, ssh itself supports this, just ~/.ssh/configadd a few lines of configuration to the file.

# 会话复制相关配置
Host *
ControlMaster auto
ControlPath /tmp/ssh-%r@%h

# 会话保持相关配置,防止长时间不操作ssh断开连接
ServerAliveInterval 10

otherprompt

Guess you like

Origin blog.csdn.net/weixin_52777294/article/details/112410350