linux ssh复制粘贴,Linux下SSH Session复制功能实现方法

特别感谢阿干同学的邮件分享。

详细方法

复制代码代码如下:

Linux/mac下,在$HOME/.ssh/config中加入

Host *

ControlMaster auto

ControlPath /tmp/ssh-%r@%h

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

配置文件分析

man ssh_config 5

复制代码代码如下:

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上通过证书的形式,可以实现免登录,没错。

对于静态密码,完全可以这么干;对于动态密码(口令的方式),则上述手段可以方便很多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值