Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1584  / 2 Years ago, wed, july 6, 2022, 10:39:48

I have created a bash script as follows and saved it as /usr/bin/db.sync.sh:



#!/bin/bash

rsync -ar --delete /files/database_backups [email protected]:/users/slyme/Documents/server_backups


I have generated the necessary pair of authentication keys to make this work without the need to enter a password.



When I run the command directly it works (hurrah!).



I have added the following to `/etc/rc.local':



/usr/bin/db.sync.sh >>/files/database_backups/db-sync.log.txt 2>&1


When I restart the machine this script fails and the log file suggests that the process asks for a password which, of course, it doesn't get so it fails. If I run /etc/rc.local from the command line then, sure enough, I get asked for a password and when I enter it the script works.



Anyone got any ideas why the script needs a password when run from rc.local even though it doesn't need a password when run directly?


More From » ssh

 Answers
0

The script /etc/rc.local is run as root. Make sure that you have the correct private key for user [email protected] installed in /root/.ssh/ (and not just in your user's $HOME/.ssh)



Alternatively, to make sure the correct private key is used, you can specify it on the rsync command line:



rsync -e "ssh -i /path/to/ssh_key" ...


Hope this helps.


[#23893] Friday, July 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raldership

Total Points: 222
Total Questions: 115
Total Answers: 124

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
raldership questions
Sat, Nov 12, 22, 12:31, 2 Years ago
Sun, Aug 8, 21, 13:07, 3 Years ago
Wed, Sep 8, 21, 08:24, 3 Years ago
;