stone2083

          Linux下SSH Session復制

          羨慕Windows下secureCRT的Session Copy功能,一直在尋找Linux下類似的軟件,殊不知SSH本身就支持此功能。
          特別感謝阿干同學的郵件分享。

          詳細方法
          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上通過證書的形式,可以實現免登錄,沒錯。
          對于靜態密碼,完全可以這么干;對于動態密碼(口令的方式),則上述手段可以方便很多。

          posted on 2011-08-25 17:02 stone2083 閱讀(3662) 評論(4)  編輯  收藏 所屬分類: linux

          Feedback

          # re: Linux下SSH Session復制 2011-08-25 22:19 gavingeng

          ssh -keygen -C 'xxx@xxx.com' -t rsa  回復  更多評論   

          # re: Linux下SSH Session復制 2011-08-26 09:04 stone2083

          @gavingeng
          不錯的方法。像開發服務器上,就可以這么干。不過對于線上環境,跳板機+動態口令,那么Session復制的方式是最理想的了。
          除了證書方式,linux下sshpass軟件,也還是不錯的。  回復  更多評論   

          # re: Linux下SSH Session復制 2011-08-26 09:59 淘寶女裝

          這個沒玩過,一般只是用SSH遠程連接  回復  更多評論   

          # re: Linux下SSH Session復制 2014-07-04 13:08 kehr

          @stone2083
          百度的?  回復  更多評論   

          主站蜘蛛池模板: 库伦旗| 平远县| 高青县| 樟树市| 阿城市| 崇仁县| 高雄县| 石景山区| 永定县| 连云港市| 康保县| 新泰市| 铜鼓县| 谢通门县| 固镇县| 浦县| 靖远县| 萨嘎县| 闸北区| 奉贤区| 柏乡县| 阳原县| 瑞金市| 武宁县| 顺昌县| 莆田市| 濮阳县| 宜兴市| 甘孜县| 青田县| 海淀区| 博湖县| 宣汉县| 翼城县| 常德市| 陈巴尔虎旗| 广宗县| 凤阳县| 神农架林区| 赤城县| 沙河市|