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 Answers1

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/

Rahul
  • 13,589