0

I got a bash script to synchronize data between two computers. It works fine but I have to type my password every time the rsync command is called.

#!/bin/bash

sourceIP="192.168.178.128"
sourceUser="user1"
destinationUser="user2"

function sync()
{
     rsync --archive --progress -v -e "ssh -l $sourceUser " $sourceIP:/home/$sourceUser/$1/ /home/$destinationUser/$1
}

sync Pictures
sync Music
sync Videos
sync Documents

How to store the password (via prompt) in a variable and pass it to rsync/ssh?

1
  • 1
    get rid of passwords. Use the keys, Luke!
    – Jakuje
    Apr 21 '16 at 11:46
4

What you really want to do is look at setting up public keys between the servers so they 'trust' each other and passwords are not needed.

Have a read here:

http://www.thegeekstuff.com/2011/07/rsync-over-ssh-without-password/

Not the answer you're looking for? Browse other questions tagged or ask your own question.