Linux下SSH Session復(fù)制功能實(shí)現(xiàn)方法
特別感謝阿干同學(xué)的郵件分享。
詳細(xì)方法
Linux/mac下,在$HOME/.ssh/config中加入
Host *
ControlMaster auto
ControlPath <a>/tmp/ssh-%r@%h</a>
至此只要第一次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 為遠(yuǎn)程機(jī)器的登錄名
%h 為遠(yuǎn)程機(jī)器名
原理分析
嚴(yán)格地講,它并不是真正意義上的Session Copy,而只能說是共享Socket。
第一次登錄的時候,將Socket以文件的形式保存到:/tmp/ssh-%r@%h這個路徑
之后登錄的時候,一旦發(fā)現(xiàn)是同個主機(jī),則復(fù)用這個Socket
故,一旦主進(jìn)程強(qiáng)制退出(Ctrl+C),則其他SSH則被迫退出。
可以通過ssh -v參數(shù),看debug信息驗(yàn)證以上過程
備注
有同學(xué)說在linux上通過證書的形式,可以實(shí)現(xiàn)免登錄,沒錯。
對于靜態(tài)密碼,完全可以這么干;對于動態(tài)密碼(口令的方式),則上述手段可以方便很多。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信