How to pass password automatically for rsync SSH command?

后端 未结 13 1658
情歌与酒
情歌与酒 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条回答
  •  猫巷女王i
    2020-12-02 06:13

    The official solution (and others) were incomplete when I first visited, so I came back, years later, to post this alternate approach in case any others wound up here intending to use a public/private key-pair:

    Execute this from the target backup machine, which pulls from source to target backup

    rsync -av --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' user@10.9.9.3:/home/user/Server/ /home/keith/Server/

    Execute this from the source machine, which sends from source to target backup

    rsync -av --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' /home/user/Server/ user@10.9.9.3:/home/user/Server/

    And, if you are not using an alternate port for ssh, then consider the more elegant examples below:

    Execute this from the target backup machine, which pulls from source to target backup:

    sudo rsync -avi --delete user@10.9.9.3:/var/www/ /media/sdb1/backups/www/

    Execute this from the source machine, which sends from source to target backup:

    sudo rsync -avi --delete /media/sdb1/backups/www/ user@10.9.9.3:/var/www/

    If you are still getting prompted for a password, then you need to check your ssh configuration in /etc/ssh/sshd_config and verify that the users in source and target each have the others' respective public ssh key by sending each over with ssh-copy-id user@10.9.9.3.

    (Again, this is for using ssh key-pairs without a password, as an alternate approach, and not for passing the password over via a file.)

提交回复
热议问题