How to pass password automatically for rsync SSH command?

后端 未结 13 1608
情歌与酒
情歌与酒 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:14

    The following works for me:

    SSHPASS='myPassword'
    /usr/bin/rsync -a -r -p -o -g --progress --modify-window=1 --exclude /folderOne -s -u --rsh="/usr/bin/sshpass -p $SSHPASS ssh -o StrictHostKeyChecking=no -l root"  source-path  myDomain:dest-path  >&2
    

    I had to install sshpass

    0 讨论(0)
  • You should use a keyfile without passphrase for scripted ssh logins. This is obviously a security risk, take care that the keyfile itself is adequately secured.

    Instructions for setting up passwordless ssh access

    0 讨论(0)
  • 2020-12-02 06:17

    Automatically entering the password for the rsync command is difficult. My simple solution to avoid the problem is to mount the folder to be backed up. Then use a local rsync command to backup the mounted folder.

    mount -t cifs //server/source/ /mnt/source-tmp -o username=Username,password=password
    rsync -a /mnt/source-tmp /media/destination/
    umount /mnt/source-tmp
    
    0 讨论(0)
  • 2020-12-02 06:18

    Another interesting possibility:

    1. generate RSA, or DSA key pair (as it was described)
    2. put public key to host (as it was already described)
    3. run:
    rsync --partial --progress --rsh="ssh -i dsa_private_file" host_name@host:/home/me/d .
    

    Note: -i dsa_private_file which is your RSA/DSA private key

    Basically, this approach is very similar to the one described by @Mad Scientist, however you do not have to copy your private key to ~/.ssh. In other words, it is useful for ad-hoc tasks (one time passwordless access)

    0 讨论(0)
  • 2020-12-02 06:20

    Following the idea posted by Andrew Seaford, this is done using sshfs:

    echo "SuperHardToGuessPass:P" | sshfs -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@example.com:/mypath/ /mnt/source-tmp/ -o workaround=rename -o password_stdin
    rsync -a /mnt/source-tmp/ /media/destination/
    umount /mnt/source-tmp
    
    0 讨论(0)
  • 2020-12-02 06:23

    I use a VBScript file for doing this on Windows platform, it servers me very well.

    set shell = CreateObject("WScript.Shell")
    shell.run"rsync -a Name@192.168.1.100:/Users/Name/Projects/test ."
    WScript.Sleep 100
    shell.SendKeys"Your_Password"
    shell.SendKeys "{ENTER}"
    
    0 讨论(0)
提交回复
热议问题