ssh自動登錄 shell實現SSH自動登錄

 

 

通過跳板機的登錄通常很麻煩,能夠使用 vbs自動登錄腳本。html

 

windows下的xshell的vbs登錄腳本shell

Sub Main
xsh.Screen.Synchronous = true

' xsh.Screen.WaitForString "resource"
xsh.screen.send "2" 
xsh.screen.send Chr(13)
xsh.Screen.WaitForString "account"
xsh.screen.send "root" 
xsh.screen.send Chr(13)
xsh.Session.Sleep 1000
xsh.Screen.WaitForString "password:"
xsh.screen.send "Root@123456" 
xsh.screen.send Chr(13)
xsh.Session.Sleep 1000
xsh.Screen.WaitForString "~$"
xsh.screen.send "ssh admin@120.16.150.141" 
xsh.screen.send VbCr 
xsh.Session.Sleep 5000
xsh.Screen.WaitForString "password:"
xsh.screen.send "Admin@123456" 
xsh.screen.send VbCr
' VbCr is equal to Chr(13)
xsh.Screen.Synchronous = false
End Sub

 

xshell下腳本不少是否無效,特別是 WaitForString  和  WaitForStrings 函數windows

 

windows下securityCRT的登錄腳本服務器

Sub Main
crt.Screen.WaitForString "select the resource" ,30
crt.screen.send "2" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "account" ,10
crt.screen.send "root" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "password" ,10
crt.screen.send "Root@123456" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "~$" ,10
crt.screen.send "ssh admin@120.16.150.141" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "assword:" ,10
crt.screen.send "Admin@123456" 
crt.screen.send Chr(13)
End Sub

 

 

參考資料:ssh

一、xShell終端調用VBS腳本 使用方法說明函數

二、 xshell官方手冊 http://www.netsarang.com/docs/Xshell5_manual.pdfpost

三、 shell實現SSH自動登錄ui

四、 【ssh】經過跳板機自動登陸目標服務器 url

相關文章
相關標籤/搜索