jejje / pihole-rsync

Setting up a sync between two PiHole for Failover
14 stars 3 forks source link

Permission denied #1

Open bahree opened 3 years ago

bahree commented 3 years ago

Hi, this is interesting and seems quite simple - thank you for sharing.

When I set this up unfortunately I get a permissions denied error when I run this - any ideas on what am I doing wrong?

Here is what I get when manually running this from the 'master pihole' to the secondary one.

pi@pi-server2:/etc/pihole $ sudo ./pi_rsync.sh -s
Syncing {gravity.db} over to {192.168.10.66}...
rsync: mkstemp "/etc/pihole/.gravity.db.UBI39Q" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
Syncing {custom.list} over to {192.168.10.66}...
rsync: mkstemp "/etc/pihole/.custom.list.qWKIPL" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
Syncing {dhcp.leases} over to {192.168.10.66}...
rsync: mkstemp "/etc/pihole/.dhcp.leases.bn9i35" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
Syncing {local.list} over to {192.168.10.66}...
rsync: mkstemp "/etc/pihole/.local.list.vwgcSi" failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
Running command pihole -g on {192.168.10.66}

Thanks.

jejje commented 3 years ago

Sorry for my late response. A permission denied would suggest that the account info is not correct.

miarn commented 3 years ago

I'm having a similar issue, but I've checked and the details are definitely correct. I can ssh from the "primary" pi-hole (192.168.1.2) to the "secondary" pi-hole (192.168.1.3) without issue.

On running the script, I'm asked for a password, but input isn't accepted.

Here's my output:

/etc/pihole ❯ sudo ./pi_rsync.sh -s
Running command service pihole-FTL stop on {192.168.1.3}
[sudo] password for [my-username]: Syncing {gravity.db} over to {192.168.1.3}...
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.3]
Syncing {custom.list} over to {192.168.1.3}...
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.3]
Syncing {local.list} over to {192.168.1.3}...
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.3]
Running command pkill pihole-FTL on {192.168.1.3}
[sudo] password for [my-username]: Running command service pihole-FTL start on {192.168.1.3}
[sudo] password for [my-username]: Running command pihole restartdns reload-lists on {192.168.1.3}
[sudo] password for [my-username]:
miarn commented 3 years ago

Having spent a bit more time looking into this, I've finally stumbled upon the (obvious) solution.

The user on the secondary Pi-Hole needs to have write access to the /etc/pihole directory, otherwise the permissions error will be displayed. As most of the files in that directory are owned by root, it's necessary to either set permissions to 777 (not good for obvious reasons) or run the rsync as the root user on the secondary Pi-Hole (also not ideal, but an OK workaround).

Also, rsync must be installed on both Pi-Holes.

jejje commented 3 years ago

What OS are you using? I used Raspian and Debian. I need to test some more and it would be good to find a solution that works for everyone and are as secure as we can manage.

scottd34 commented 1 year ago

I know this thread is old but the /etc/pihole folder is set for pihole:pihole so one solution is to add the pi user to the pihole group. From there the script works properly.

kshitijmjoshi commented 10 months ago

@miarn After stupidly struggling for a few hours trying to modify the script to get it working, finally realized the issue after reading your comment. Thank you!