automatically pass a password to rsync for remote host.
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
automatically pass a password to rsync for remote host.
Hi all,
I need to be able to use an rsync command in script that will be run by cron. And it needs to be able to pass a password to rsync so that the remote server it's connecting to will authenticate.
I cannot set up ssh keys between the two servers, it's not an option.
I cannot use any other language other than bash, it's my only option.
I know this is highly insecure, I have no other option.
So far I have this:
rsync --rsh="/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password" -raxv /source/dir/* user@remotehost:/target/directory/.
This allows the script to ignore host verification and goes directly to the password prompt. I need the script to fill in this password prompt with the password that is stored in a variable.
I tried using expect, but I honestly don't know the syntax, it just keeps failing. A lot of the examples I'm finding online for expect starts off with a "spawn", which i don't have installed, and not sure if I have the ability to install it yet.
expect -f tmp
spawn rsync --rsh="/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password" -raxv /source/dir/* user@remotehost:/target/directory/.
Missing trailing-" in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(335) [sender=2.6.8]
send: spawn id exp6 not open
while executing
"send blarg\n"
(file "tmp" line 3)
I'm SURE I'm messing something up, I've seen a dozen ways to use execpt online, and can't get any to work. My brain is fried so I'll be revisiting this tomorrow.
alright I couldn't leave it alone, but as luck would have it, I found http://rootprompt.org/article.php3?article=5760, which finally had a working example for me since I've never used expect.
with that, I wrote up this. I couldn't seem to execute it all as a 'string', so wrote it to a file, executed it, then removed it. It's dirty but it will do for now.
Code:
#!/bin/bash
pass=password
expect="""#!/usr/bin/expect -f
set timeout -1
spawn rsync -ravx user@host:from/* to/.
expect \"password:\" { send \"$pass\\n\"}
expect \"#\"
"""
echo "$expect" > /tmp/temp.sh
chmod 777 /tmp/temp.sh
/tmp/temp.sh
echo "result is [$?]"
if [[ $result -eq 0 ]]; then
echo "Success"
else
echo "Failure"
fi
rm -f /tmp/temp.sh
I'd like to get it to execute with except -f, but I'll mess with that later, for now it actually works, so I'm not freaking out :-)
I cannot set up ssh keys between the two servers, it's not an option.
What about hostbased authentication? Or running rsync in daemon mode on the target machine and expect a password for connections, which you can set in the cron entry by just setting an environment variable. I do it this way like:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.