Permission denied (publickey, password)
probably, authentication should be performed on a pair of a secret-public key.
for this, either the rsync program must explicitly specify the secret key, or it will use the fact that it is located in the ~/.ssh the user on whose behalf it is running.
most likely, the cron job is performed on behalf of the root user (and in the terminal emulator, on behalf of the “ordinary” user). therefore, rsync and “does not find” a suitable secret key.
solutions (in order of "decreasing rationality" from my point of view):
Write the task itself to the crontab file of the desired user by running the following command on behalf of this user (and not root ):
$ crontab -e
run the rsync program on behalf of the user using the sudo program:
sudo -u пользователь rsync ...
specify the rsync program (more precisely, the ssh program it calls ) the file with the secret key (for example, /home/пользователь/.ssh/id_rsa ), adding the option -e команда :
rsync -e 'ssh -i /home/пользователь/.ssh/id_rsa' ...
Copy the secret key from the directory of an "ordinary" user to the directory of the root user (creating a directory if necessary and setting up the "correct" rights for it and its content):
$ sudo mkdir -p /root/.ssh $ sudo cp /home/пользователь/.ssh/id_rsa /root/.ssh $ sudo chown -R root:root /root/.ssh $ sudo chmod -R go= /root/.ssh
if, as written in the comments, cron performs a task from the same user as when starting up in the terminal emulator, then you should compare the output of the env command, executed in the terminal emulator and the cron program. some key (for the script being executed) variables are present in one place and absent (or have a different meaning) - in another. it is more convenient to compare the diff -ruaN файл1 файл2 , having previously sorted both files by the sort program.
First of all, you should pay attention to the presence and value of the HOME variable. for by default, the secret key is searched for in the $HOME/.ssh .
env &> log.txt- sergw in the script