15

What are the reasons that could make a change in a file ownership after scp'ing it from one server to another?

The file ownership changed from 'owner' to 'apache'. I used scp -p . The user 'owner' exists on both servers and has the same UID.

1
  • 1
    Just tar the files you want to copy with -p, scp the tar, and untar on the destination with -p as well.
    – Prime
    Dec 20, 2018 at 12:04

2 Answers 2

14

From man scp:

-p      Preserves modification times, access times, and modes from the
        original file.

You can see the -p option does not preserve ownership.

If you want to preserve file ownership, you can use rsync with -o and -g, which will preserve owner and group. This requires you to run rsync as root.

8

When you scp, the ownership comes from the user you use to scp to the other machine. For example:-

scp FILENAME USER@HOSTNAME:/PATH/TO/DESTINATION/

The ownership of FILENAME at the host HOSTNAME after scp will be USER as owner and primary group of USER as its group ownership.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .