rsync over SSH preserve ownership only for www-data owned files

后端 未结 6 1562
轮回少年
轮回少年 2021-02-05 16:36

I am using rsync to replicate a web folder structure from a local server to a remote server. Both servers are ubuntu linux. I use the following command, and it works well:

6条回答
  •  难免孤独
    2021-02-05 16:55

    The root users for the local system and the remote system are different.

    What does this mean? The root user is uid 0. How are they different?

    Any user with read permission to the directories you want to copy can determine what usernames own what files. Only root can change the ownership of files being written.

    You're currently running the command on the source machine, which restricts your writes to the permissions associated with user@10.1.1.1. Instead, you can try to run the command as root on the target machine. Your read access on the source machine isn't an issue.

    So on the target machine (10.1.1.1), assuming the source is 10.1.1.2:

    # rsync -az user@10.1.1.2:/var/www/ /var/www/
    

    Make sure your groups match on both machines.

    Also, set up access to user@10.1.1.2 using a DSA or RSA key, so that you can avoid having passwords floating around. For example, as root on your target machine, run:

    # ssh-keygen -d
    

    Then take the contents of the file /root/.ssh/id_dsa.pub and add it to ~user/.ssh/authorized_keys on the source machine. You can ssh user@10.1.1.2 as root from the target machine to see if it works. If you get a password prompt, check your error log to see why the key isn't working.

提交回复
热议问题