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

前端 未结 9 818
轮回少年
轮回少年 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:44

    The easiest way is to use sshpass. This is available in Ubuntu/Debian repositories and you don't have to deal with integrating expect with Bash.

    An example:

    sshpass -p ssh 
    sshpass -ptest1324 ssh user@192.168.1.200 ls -l /tmp
    

    The above command can be easily integrated with a Bash script.

    Note: Please read the Security Considerations section in man sshpass for a full understanding of the security implications.

提交回复
热议问题