UID mapping with rsync

5,080

rsync does what you want if you give -a. Actually, you only need -o and -g, but since you're trying to preserve this much, you probably want the rest of what -a provides.

Obviously you need root permissions on the remote side for this to work. This means you need to log in as root on the remote system if rsyncing over SSH. If you're running rsync as a daemon on the remote system instead, it needs to run as root.

Share:
5,080

Related videos on Youtube

CharlesB
Author by

CharlesB

Updated on September 18, 2022

Comments

  • CharlesB
    CharlesB almost 2 years

    I'm migrating files between servers and have to map UIDs (add 500) and GIDs. As I'd like to have it done in one single pass, is there a way to execute a command for each file rsync copies?

  • CharlesB
    CharlesB over 12 years
    rsync doesn't do the right thing for me (I have same usernames, only uid differ). I guess rsync can't map them as users are now stored in LDAP...
  • Warren Young
    Warren Young over 12 years
    Sorry, I was mislead by the docs and the fact that I always use -a in my rsync commands. Rewrote my answer. I think you'll find that with -a and root permission on the remote system, you get the behavior you want despite using LDAP.
  • CharlesB
    CharlesB over 12 years
    I'm syncing over NFS (one of the server is an atom NAS, and SSH tunnel is kill bandwidth), and good Lord after retrying with SSH it works! I suppose I have to look into RSH, as I'll have both transfer speed and UID mapping, right?
  • Warren Young
    Warren Young over 12 years
    If you don't need the encryption provided by SSH, I'd suggest using rsync in daemon mode on the server side. RSH is rightly deprecated as horribly insecure.
  • Warren Young
    Warren Young over 12 years
    Are you sure rsyncd is running as root on the remote system? It doesn't by default. Only root can change a file's owner.
  • CharlesB
    CharlesB over 12 years
  • Admin
    Admin over 11 years
    To get user mapping from an rsyncd server, you mustn't chroot it. It doesn't need to be root just to be able to read the source file, anybody can read the password file (or getpwent equivalent).