0

I am developing a script that will automatically keep a folder on two workstations synchronized using rsync. So far, I have gotten everything to work but I have one small thing I haven't figured out. Once, the rsync command is executed, it prompts for the password of the other workstation. However, I haven't been able to find a way to automatically enter that password once prompted in the terminal. I tried using the expect command, but that didn't work as the command didn't execute until after I enter the password.

Is there a solution to this?

Here is my script. I have two instances of the same VM, hence the same usernames

#!/bin/bash
LOCAL="/home/rams/Documents/"
RSYNC_OPTIONS="-avh --progress /home/rams/Documents/ rams@192.168.1.39:/home/rams/Downloads/"
PASSWORD="rams2020"

while true
do
    inotifywait -e modify $LOCAL
    rsync $RSYNC_OPTIONS
done
  • 1
    Welcome to SO! You should use a keyfile without passphrase for scripted ssh logins. Since this is a security risk, make sure that the keyfile itself is adequately secured. For instructions how to do that, check out this answer https://stackoverflow.com/a/3299970/8860865 – Thomas Hansen Jan 12 '21 at 18:54
  • This was it! Thank you @ThomasHansen – itanitarek10 Jan 12 '21 at 19:02

1 Answers1

1

Solution shown here:

https://stackoverflow.com/a/3299970/8860865

TL;DR - Use an SSH keygen to generate a keyfile that will authenticate upon using the rsync command and the password is prompted. https://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/