The realization method of SSH Session replication function under Linux
This article mainly explains "the implementation of SSH Session replication function under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "the implementation of SSH Session replication function under Linux"!
The code is as follows:
Under Linux/mac, add to $HOME/.ssh/config
Host *
ControlMaster auto
ControlPath / tmp/ssh-%r@%h
At this point, as long as you enter the password for the first SSH login, then the same Hosts will not be logged in.
Profile analysis
Man ssh_config 5
The 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 "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 really Session Copy, but can only be said to be a shared Socket.
When you log in for the first time, save Socket as a file to the path: / tmp/ssh-%r@%h
When logging in later, once the same host is found, the Socket will be reused.
Therefore, once the main process is forced to exit (Ctrl+C), other SSH is forced to exit.
The above process can be verified by ssh-v parameter and debug information.
At this point, I believe you have a deeper understanding of "the implementation of SSH Session replication under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!