0

I need to run baskup bash script on Centos 6.6 in crontab from root with rsync command: rsync -avzPX --update --exclude 'www/bitrix/backup' --exclude 'www/bitrix/managed_cache' --exclude 'www/bitrix/cache' --exclude 'www/bitrix/stack_cache' -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' /home/bitrix/ [email protected]:/home/bitrix/

I do:

ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

then i try to login with user backup, but it still asks for password.

What am I doing wrong?

6
  • in the -e 'ssh ... bit you may want to add the -i option and full path to the private key you want to use
    – HBruijn
    Aug 8, 2016 at 13:42
  • i try to do ssh [email protected] but it also doesn't work Aug 8, 2016 at 13:45
  • Then debug (use a -v flag in the ssh client) and check the remote server logs and settings, public key auth may be disabled.
    – HBruijn
    Aug 8, 2016 at 13:49
  • if encryption and authentication is unimportant to you, you might also want to try rsyncd on your server, exporting the target folder as a rsync module. you can copy to rsync modules by prepending the name with :: instead of : for ssh transport.
    – user134450
    Aug 8, 2016 at 14:23
  • do you have ssh-agent running on your machine? ssh will always try the agent first for authentication unless told not to.
    – user134450
    Aug 8, 2016 at 14:30

2 Answers 2

0

This may give a hint to the solution: Key authentication not working when using ssh or rsync as sudo

When run from a cron (which does not set up a full environment), some things may need to be explicitly specified, such as key. In this case, I would add -i /home/backup/.ssh/id_rsa to make sure it is using the correct key from the directory. You aren't passing the key file to the ssh command, and since USER or HOME may not be set in the cron environment, it probably isn't being used.

1
0

The problem was with permissions for home directory:

[root@bitrix2 home]# tail -10 /var/log/secure
Aug  9 10:19:59 bitrix2 sshd[14294]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:24:13 bitrix2 sshd[14401]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:24:13 bitrix2 sshd[14401]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:24:14 bitrix2 sshd[14402]: Connection closed by 10.10.10.4
Aug  9 10:27:31 bitrix2 sshd[14454]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:27:31 bitrix2 sshd[14454]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:29:08 bitrix2 sshd[14455]: Connection closed by 10.10.10.4
Aug  9 10:29:12 bitrix2 sshd[14490]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:29:12 bitrix2 sshd[14490]: Authentication refused: bad ownership or modes for directory /home/backup
Aug  9 10:31:13 bitrix2 su: pam_unix(su:session): session closed for user backup

Then I checked permissions:

[root@bitrix2 home]# ls -la backup
drwxr-x--x   4 backup backup 4096 Авг  9 10:09 backup

And gave normal permissions:

[root@bitrix2 home]# chmod go+xr-w backup
[root@bitrix2 home]# chmod a+rx-w backup
[root@bitrix2 home]# ls -la
drwxr-xr-x   4 backup backup 4096 Авг  9 10:09 backup

Now it works fine

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .