Reputation: 787
I have a shared SSH keys with another server so I can login without a password. Executing:
rsync -avze ssh --blocking-io --delete --rsh='ssh -p2020' [email protected]:/foo/* /bar/;
Runs fine. No password prompt. But that command in a bash file:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
rsync -avze ssh --blocking-io --delete --rsh='ssh -p2020' [email protected]:/foo/* /bar/;
Run like so:
sudo ./copyfiles.sh
Gives me this:
[email protected]'s password:
Any ideas why?
Upvotes: 1
Views: 901
Reputation: 10522
The sudo
program is probably creating a new shell without some SSH environment variables.
Try
sudo -E ./copyfiles.sh
Upvotes: 0
Reputation: 38205
You seem to be running the script as root (sudo
) but run the command line as some other user (this is just a guess). Most likely, the public key of the root user is not present on the destination machine.
Upvotes: 3