Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

rsync does not preserve permissions [SOLVED]

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
15 posts • Page 1 of 1
Author
Message
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

rsync does not preserve permissions [SOLVED]

  • Quote

Post by halcon » Fri Feb 27, 2026 2:22 pm

Hello.

The issue seems to be easy to resolve, but I can't get what is the trick.

I launch it as:

Code: Select all

/usr/bin/rsync -avhRz --delete --delete-excluded --exclude-from="/some/path/to/exclude/list" --rsync-path="sudo rsync" -e "ssh -i /home/myuser/.ssh/mykey" myuser@myipaddress:/some/path/at/source /some/path/at/destination 2>&1 | tee -a /some/path/to/log
from user "myuser" (non-root, but in group wheel)

Other details:
- both machines run Gentoo
- both machines have user "root", user "myuser", and many other users coincide
- the destination folder resides on a partition EXT4, mounted just with parameters rw,relatime - nothing mask
- the source machine has an entry in visudo myuser myhostname=(root) NOPASSWD: /usr/bin/rsync

And ALL the files and folders at the destination have permissions myuser:myuser, including those that are of root.

If I remove "2>&1", no error appears.

Why is it so?
Last edited by halcon on Fri Feb 27, 2026 4:35 pm, edited 1 time in total.
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Feb 27, 2026 2:58 pm

That's one complicated command, is there really no way to simplify it with basic syntax?

Anyway, you're missing -p
As long as all files belong to your user and groups you are a member of (on the destination machine), it should do the trick. Anything that does not belong to you will fail, because unprivileged users can't cede ownership.
Make Pipewire a system service
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Feb 27, 2026 3:04 pm

The shown command has -a, which per man rsync, is short for -rlptgoD, so -p is implicit.

halcon: does this work properly if root on the local machine syncs to root on the remote machine, thereby removing all use of sudo and --rsync-path from the process? Similarly, I note that OP says that the source user has sudo permission, but is silent on whether the destination user has it. Presumably, sudo should have printed an error message and exited failure if not, and OP says there are no errors shown.
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 3:06 pm

szatox wrote:That's one complicated command, is there really no way to simplify it with basic syntax?
Do you have suggestions?
szatox wrote:Anyway, you're missing -p
AFAIK, I am not. The option -a includes it. From man rsync:

Code: Select all

--archive, -a            archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
szatox wrote:As long as all files belong to your user and groups you are a member of (on the destination machine), it should do the trick. Anything that does not belong to you will fail, because unprivileged users can't cede ownership.
Do you want to say that I should rsync as (destination) root?
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 3:09 pm

Hu wrote:halcon: does this work properly if root on the local machine syncs to root on the remote machine, thereby removing all use of sudo and --rsync-path from the process?
So far, I don't know. I didn't open SSH access for root on the source machine for security reasons.
Hu wrote:Similarly, I note that OP says that the source user has sudo permission, but is silent on whether the destination user has it. Presumably, sudo should have printed an error message and exited failure if not, and OP says there are no errors shown.
I don't have any sudo permissions for "muyser" on the destination machine. So, should I?
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 3:22 pm

I have added the same visudo record for myuser at the destination machine (only hostname changed), launched a new terminal (graphical) for it, repeated the same rsync command, and nothing changed. I am not sure, maybe I have to update some environment.
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Feb 27, 2026 3:40 pm

Normally, all users have outbound access unrestricted, so there is nothing to do on the source machine to let root run ssh destination-ip. Did you try that and observe it to fail locally?

If you don't have sudo on the remote machine, why would you tell the local rsync to run sudo rsync on the remote machine? That will just fail, although it should have failed in a way that produced an obvious error.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Feb 27, 2026 3:45 pm

Right, -a includes -p, my bad.
Well, if you want to preserve permissions, running as root is the natural choice. However, you might also try --super to either get better results of or an error (hopefully) telling you what's wrong. BTW, a --fake-super option exists too, and it exploits extended attributes to store metadata it may not be allowed to write directly.
Make Pipewire a system service
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 3:48 pm

Hu wrote:If you don't have sudo on the remote machine, why would you tell the local rsync to run sudo rsync on the remote machine? That will just fail, although it should have failed in a way that produced an obvious error.
On the remote machine I had it from the beginning. The remote is source. The destination is local. I am "pulling": launching rsync at my local machine for making a backup of a server. The local launcher initially was just a user "myser" in the wheel group. And now I've added a sudo record for him too - nothing changed.
Hu wrote:Normally, all users have outbound access unrestricted, so there is nothing to do on the source machine to let root run ssh destination-ip. Did you try that and observe it to fail locally?
Outbound, if launching from the same server? Like "pushing" a backup? And I do "pulling" ^^ Or maybe I don't understand something :roll: Also, the destination-ip would be my home machine with a dynamic IP... Yes, I can use VPN, but...
Last edited by halcon on Fri Feb 27, 2026 3:57 pm, edited 1 time in total.
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 3:55 pm

szatox wrote:However, you might also try --super to either get better results of or an error (hopefully) telling you what's wrong.
Aha! With the option --super I've got a bunch of errors

Code: Select all

rsync: [receiver] chown "/some/file" failed: Operation not permitted (1)

Now I have where to dig further... :)
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Feb 27, 2026 4:03 pm

chown failed, so is that file really yours?

Wait...
And ALL the files and folders at the destination have permissions myuser:myuser, including those that are of root.
It wsn't clear the the first glance, but do I get it right that you knew in advance that some files you're trying to copy don't belong to your user?
This is not going to work without root privileges. You can make a backup with --fake-super at the destination (and then restore with --fake-super at the source and --super at destination), but you can't make an exact copy directly without root.
Last edited by szatox on Fri Feb 27, 2026 4:07 pm, edited 1 time in total.
Make Pipewire a system service
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 4:06 pm

szatox wrote:chown failed, so is that file really yours?

Wait...
And ALL the files and folders at the destination have permissions myuser:myuser, including those that are of root.
It wsn't clear the the first glance, but do I get it right that you knew in advance that some files you're trying to copy don't belong to your user?
This is not going to work without root privileges.
Yeah, evidently, I failed to describe it correctly. I meant "And ALL the files and folders, including those root:root, become after rsyncing myuser:myuser". Is it correct now? :roll:

EDIT
But it really worked. I got all these root files, they just didn't preserve root permissions.

EDIT2
On the server:

Code: Select all

# LC_ALL=C ls -al /root/.bash_history
-rw------- 1 root root 26014 Feb 27 19:15 /root/.bash_history
On the local machine:

Code: Select all

# LC_ALL=C ls -al .bash_history 
-rw------- 1 myuser myuser 23336 Feb 27 09:06 .bash_history
Last edited by halcon on Fri Feb 27, 2026 4:45 pm, edited 2 times in total.
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Feb 27, 2026 4:16 pm

Yeah, you're running the remote rsync via sudo, so with root access. Of course this part works.
You still can't write permissions locally as a regular user. This part doesn't go through sudo in your command, and you said you're running it as a regular user. Wheel has nothing to do with it unless you actually use that membership to run rsync via su.

If you want to have 2 usable copies, you have to run both sides a root.
Make Pipewire a system service
Top
Anon-E-moose
Watchman
Watchman
User avatar
Posts: 6566
Joined: Fri May 23, 2008 7:31 pm
Location: Dallas area

  • Quote

Post by Anon-E-moose » Fri Feb 27, 2026 4:28 pm

If I am not mistaken you can't write root permissions (owner, etc) as a user. (not even rsync can do it)
UM780 xtx, 6.18 zen kernel, gcc 15, openrc, wayland
minixforum m1-s1 max -- same software as above but used for ai learning


Zealots are gonna be zealots, just like haters are gonna be haters
Top
halcon
l33t
l33t
User avatar
Posts: 736
Joined: Sun Dec 15, 2019 8:54 pm

  • Quote

Post by halcon » Fri Feb 27, 2026 4:35 pm

Anon-E-moose wrote:If I am not mistaken you can't write root permissions (owner, etc) as a user. (not even rsync can do it)
Right, rsync can't. I tried adding sudo for rsync, and for chown.
szatox wrote:If you want to have 2 usable copies, you have to run both sides a root.
I just copied my ~/.ssh to /root, re-run rsync as root, and it is OK now :)
So, not necessarily both root. Local launching root + remote user with sudo = success.

Marking as solved.

Thank you all !
A wife asks her husband, a programmer:
- Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?
He comes back with 6 cartons of milk.
- Why did you buy 6 cartons of milk?
- They had eggs.
Top
Post Reply

15 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic