这是我的拓扑:
My laptop ==> Ubuntu Desktop
| | |
User: root & saeed
My server ==> Ubuntu 20.04
| | |
Users: root & ubuntu (I deleted it as I explain below)
步骤:
- 我
tar zvcf back.tar.gz .
在我的笔记本电脑上以用户身份运行saeed
并创建了文件。 - 我使用
root
路径示例中的用户/home/test
(不是任何用户的主目录)通过 SFTP 将此文件上传到我的服务器。 - 我提取
back.tar.gz
了/home/test
但我发现所有文件和目录的所有者都是ubuntu:ubuntu
。 - 我删除了
ubuntu
用户并尝试了第三步,但得到了相同的结果。 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.