linux 使用tcl腳本自動ssh登錄服務器,不必每次都輸入密碼。
=============================================
首先要安裝expect包(ubuntu)
sudo aptitude install expect
登錄腳本(名爲Ssh):
#!/usr/bin/expect -f
set password 111111
set user_host [lindex $argv 0]
set timeout 50
spawn ssh $user_host -X
expect {
"(yes/no)?" {
send "yes\r"
set timeout 50
expect "$user_host's password: " {
send "$password\r"
}
}
"$user_host's password: " {
send "$password\r"
}
}
expect "*Last login:*"
interact
注意:密碼明文存儲,你的服務器密碼可能不是111111,記得替換。
使用腳本
Ssh <用戶名>@<機器名或IP>
和ssh命令用法類似