Ubuntu 中提取文件所有者后更改为不相关的用户

Ubuntu 中提取文件所有者后更改为不相关的用户

这是我的拓扑:

My laptop ==> Ubuntu Desktop
| | |
User: root & saeed

My server ==> Ubuntu 20.04
| | |
Users: root & ubuntu (I deleted it as I explain below)

步骤:

  1. tar zvcf back.tar.gz .在我的笔记本电脑上以用户身份运行saeed并创建了文件。
  2. 我使用root路径示例中的用户/home/test(不是任何用户的主目录)通过 SFTP 将此文件上传到我的服务器。
  3. 我提取back.tar.gz/home/test但我发现所有文件和目录的所有者都是ubuntu:ubuntu
  4. 我删除了ubuntu用户并尝试了第三步,但得到了相同的结果。
  5. back.tar.gz我在笔记本电脑的另一个路径中提取,但所有文件的所有者都是saeed:saeed

为什么会发生这种情况?

答案1

以 root 身份提取时,tar默认情况下会保留原始所有者 ID。用户saeed恰好与另一台计算机上的用户 ID 相同ubuntu(可能也是如此1000)。您可以通过运行来检查 ID id saeed,或者只id检查当前用户。

如果你不想保留用户 ID,那么不要以 root 身份提取,或者使用选项--no-same-owner。相关片段来自手动的

       --no-same-owner
              Extract files as yourself (default for ordinary users).

对于常规用户可以实现相反的效果--same-owner

创建档案时可以使用的相关选项--owner--owner-map

       --owner=NAME[:UID]
              Force NAME as owner for added files.  If UID is not
              supplied, NAME can be either a user name or numeric UID.
              In this case the missing part (UID or name) will be
              inferred from the current host's user database.

              When used with --owner-map=FILE, affects only those files
              whose owner is not listed in FILE.

       --owner-map=FILE
              Read owner translation map from FILE.  Empty lines are
              ignored.  Comments are introduced with # sign and extend
              to the end of line.  Each non-empty line in FILE defines
              translation for a single UID.  It must consist of two
              fields, delimited by any amount of whitespace:

              OLDUSR NEWUSR[:NEWUID]

              OLDUSR is either a valid user name or a UID prefixed with
              +.  Unless NEWUID is supplied, NEWUSR must also be either
              a valid user name or a +UID.  Otherwise, both NEWUSR and
              NEWUID need not be listed in the system user database.

              As a result, each input file owned by OLDUSR will be
              stored in archive with owner name NEWUSR and UID NEWUID.

相关内容