Use Expect in a Bash script to provide a password to an SSH command

前端 未结 9 814
轮回少年
轮回少年 2020-11-22 06:23

I\'m trying to use Expect in a Bash script to provide the SSH password. Providing the password works, but I don\'t end up in the SSH session as I should. It goes back strait

9条回答
  •  不知归路
    2020-11-22 06:53

    A simple Expect script:

    File Remotelogin.exp

        #!/usr/bin/expect
        set user [lindex $argv 1]
        set ip [lindex $argv 0]
        set password [lindex $argv 2]
        spawn ssh $user@$ip
        expect "password"
        send "$password\r"
        interact
    

    Example:

    ./Remotelogin.exp   
    

提交回复
热议问题