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

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

    sshpass is broken if you try to use it inside a Sublime Text build target, inside a Makefile. Instead of sshpass, you can use passh: https://github.com/clarkwang/passh

    With sshpass you would do:

    sshpass -p pa$$word ssh user@host
    

    With passh you would do:

    passh -p pa$$word ssh user@host
    

    Note: Do not forget to use -o StrictHostKeyChecking=no. Otherwise, the connection will hang on the first time you use it. For example:

    passh -p pa$$word ssh -o StrictHostKeyChecking=no user@host
    

    References:

    1. Send command for password doesn't work using Expect script in SSH connection
    2. How can I disable strict host key checking in ssh?
    3. How to disable SSH host key checking
    4. scp without known_hosts check
    5. pam_mount and sshfs with password authentication

提交回复
热议问题