Let's say that there are two dedicated servers, freshly installed, with identical software and users on both of them.
Suppose that, for whatever reason, I would like to copy ownership patterns from one of these servers to another. Is that possible?
Let's say that there are two dedicated servers, freshly installed, with identical software and users on both of them.
Suppose that, for whatever reason, I would like to copy ownership patterns from one of these servers to another. Is that possible?
The first paragraph makes hardly any sense, but your actual question:
Can I recover and set up file permissions and ownerships using another server as a reference/template?
The short answer is: maybe...
The longer answer is that such a strategy will fail for every file that does not exist on both servers. And as far as scripting goes, you'll need to take particular good care with special files, (symbolic) links, special characters in file/directory names etc. etc.
But both the chmod
and chown
commands support a --reference
flag. You can point to an existing file and chmod
will use the permissions of that file instead of you needing to supply MODE values when changing the file mode.
Similarly chown
will use owner and group of that reference file/directory rather than specifying OWNER:GROUP values.
The exercise is then:
find
commands that execute chown
and chmod
:(Please note that these are only conceptual and untested. Please add restrictions for find
to only locate files and directories for instance and omit following symbolic links and such... )
To reset ownerships and modes on a corrupted /etc/
:
cd /template/etc
find . -exec chmod -v --reference='{}' /etc/'{}' \;
find . -exec chown -v --reference='{}' /etc/'{}' \;