Implementation method of SSH session replication function under Linux

Source: Internet
Author: User

Special thanks to Agan for your email sharing.

  Detailed method

The code is as follows:

Linux/mac, add in $home/.ssh/config

Host *

Controlmaster Auto

Controlpath /tmp/ssh-%r@%h

So long as the first SSH login to enter the password, then the same hosts are exempt.

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 None "to disable Connection Sharing. In the path, '%l ' is substituted by the

Local host name, '%h ' would be substituted by the target host name, ' %p ' The port, and '%r ' by the remote

Login username. It is recommended so any controlpath used to opportunistic connection sharing include at

Least%h,%p, and%r. This is ensures that shared connections are uniquely identified.

%r to the remote machine's logon name

%h to remote machine name

principle Analysis

Strictly speaking, it is not really a session Copy, but rather a shared socket.

When you first log in, save the socket as a file to:/tmp/ssh-%r@%h This path

And when you log on, once you find the same host, reuse this socket

So once the main process forces the exit (Ctrl +C), other SSH is forced to quit.

You can see the debug information validation process

by ssh-v parameters Note

Some students say that the form of a certificate on Linux, you can achieve a login-free, yes.

Can be done completely for static passwords, and for dynamic passwords (the way passwords are), the above methods can be much easier.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.