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

 

你可能感兴趣的:(expect脚本实现ssh自动登录)