Linux SSH Session replication function implementation method

  
        Special thanks to Agan’s email sharing.
Detailed Method
The code is as follows:
Linux/mac, add $HOME/.ssh/config Host *
ControlMaster auto
ControlPath /tmp/ssh-%r @%h
At this point, as long as the first SSH login enters the password, the same Hosts will be waived.
Profile Analysis
man ssh_config 5
Code is as follows:
ControlPath
Specify the path to the control socket used for connection sharing as described in the ControlMaster section
above or the string &ldquo ;none” to disable connection sharing. In the path, ‘%l’ will be substituted by the
local host name, ‘%h’ will be substituted by the target host name, ‘%p’ the port , and ‘%r’ by the remote
login username. It is recommended that any ControlPath used for opportunistic connection sharing include at
least %h, %p, and %r. This ensures that shared connections are uniquely Identified.
%r is the login name of the remote machine
%h is the remote machine name
Principle Analysis
Strictly speaking, it is not a true Session Copy, but can only be said to be shared Socket.
When logging in for the first time, save the Socket as a file to: /tmp/ssh-%r@%h

After logging in, once it is found to be the same host, reuse this Socket
Therefore, once the main process is forced to exit (Ctrl+C), other SSHs are forced to exit.
You can use the ssh -v parameter to see the debug information to verify the above process
Remarks
Some students say that in the form of a certificate on Linux, you can achieve login-free, yes.
For static passwords, you can do this completely; for dynamic passwords (passwords), the above means can be much more convenient.

Copyright © Windows knowledge All Rights Reserved