欢迎来到李先生的博客

深山的鹿,不知归处;万般皆苦,只可自渡。
扩大
缩小

expect脚本实现ssh自动登录

1:简单的实现ssh登录

   #!/usr/bin/expect
    set ip "10.0.0.142"
    set user "root"
    set password "123456"
    spawn ssh $user@$ip
    expect {
    "yes/no"{ send "yes\n";exp_continue }
    "password:"{ send "$password\r"}
    }
    interact

 

2:实现ssh防止泄露密码,作为参数手动输入 [lindex $argv 0]
    #!/usr/bin/expect
    #Achieve ssh auto login
    #This is the Achieve ssh auto login shell
    #USEAGE: expect $0 secrect,eg expect $0 123456
    set ip "10.0.0.142"
    set user "root"
    set password [lindex $argv 0]
    spawn ssh $user@$ip
    expect {
    "yes/no"{ send "yes\n";exp_continue }
    "password:"{ send "$password\r"}
    }
    interact

 

posted on 2017-03-03 09:30  Captain_Li  阅读(799)  评论(0编辑  收藏  举报

导航