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命令用法类似