How to pass password automatically for rsync SSH command?

后端 未结 13 1657
情歌与酒
情歌与酒 2020-12-02 05:39

I need to do rsync by ssh and want to do it automatically without the need of passing password for ssh manually.

13条回答
  •  我在风中等你
    2020-12-02 06:11

    If you can't use a public/private keys, you can use expect:

    #!/usr/bin/expect
    spawn rsync SRC DEST
    expect "password:"
    send "PASS\n"
    expect eof
    if [catch wait] {
        puts "rsync failed"
        exit 1
    }
    exit 0
    

    You will need to replace SRC and DEST with your normal rsync source and destination parameters, and replace PASS with your password. Just make sure this file is stored securely!

提交回复
热议问题