3

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/id_rsa.pub' <username>@xx.xxx.xx.xx:<filename> <filename>

Any help will be greatly appreciated

2
  • Does ssh without using cron work?
    – Elizafox
    Jul 28, 2016 at 20:26
  • Just in case this isn't properly passphraseless (eg using ssh-agent) you can test from the command line with env -i ./yourscript.sh so that it runs in a clean environment. If that works properly then you should test under cron with ssh -vv to get more debugging output. Jul 28, 2016 at 20:53

1 Answer 1

3

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/id_rsa.pub.

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>@xx.xxx.xx.xx:<filename> <filename>
2
  • If the script really is running as user <username> then the whole -i /home/<username>/.ssh/id_rsa bit is irrelevant anyway. Jul 28, 2016 at 22:03
  • Thank you heemayl, using the private key did the trick. Jul 29, 2016 at 0:37

You must log in to answer this question.

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