[转]Linux下SSH Session复制

羡慕Windows下secureCRT的Session Copy功能,一直在寻找Linux下类似的软件,殊不知SSH本身就支持此功能。
特别感谢阿干同学的邮件分享。

详细方法

1
2
3
4
Linux/mac下,在$HOME/.ssh/config中加入
Host *
ControlMaster auto
ControlPath /tmp/ssh-%r@%h

至此只要第一次SSH登录输入密码,之后同个Hosts则免登。

配置文件分析

man ssh_config 5

1
2
3
4
5
6
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 为远程机器的登录名
%h 为远程机器名


原理分析

严格地讲,它并不是真正意义上的Session Copy,而只能说是共享Socket。
第一次登录的时候,将Socket以文件的形式保存到:/tmp/ssh-%r@%h这个路径
之后登录的时候,一旦发现是同个主机,则复用这个Socket
故,一旦主进程强制退出(Ctrl+C),则其他SSH则被迫退出。

可以通过ssh -v参数,看debug信息验证以上过程

 

备注

有同学说在linux上通过证书的形式,可以实现免登录,没错。
对于静态密码,完全可以这么干;对于动态密码(口令的方式),则上述手段可以方便很多。

posted @   killkill  阅读(3609)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示