passphraseless access to rsync with ssh through cron fails

I have setup ssh keys without a passphrase (Ubuntu) and copied them to my remote server (Centos6). I can login with ssh without a password successfully under my username.

When I execute the following script in a terminal under my username (not root) it works. When I execute it through cron under my user name it fails with response:

Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 

Here is the script:

#!/bin/bash export PATH=/home/<username>/git/kodi-playercorefactory/bash-scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin rsync -rvzO  -e 'ssh -p 6135 -i /home/<username>/.ssh/' <username><filename> <filename> 

Any help will be greatly appreciated


The -i option of ssh is supposed to input the file name that contains the private key, not public key. But you have presumably given the file name containing the public key, given by the name /home/<username>/.ssh/

Assuming the private key is in /home/<username>/.ssh/id_rsa, the following should work:

rsync -rvzO  -e 'ssh -p 6135 -i /home/<username>/.ssh/id_rsa' <username><filename> <filename>

Category: ssh Time: 2016-07-28 Views: 0
Tags: ssh rsync cron

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.173 (s). 12 q(s)