これが私のトポロジーです:
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
て3番目の手順を試しましたが、同じ結果になりました。 back.tar.gz
ラップトップの別のパスに解凍しましたが、すべてのファイルの所有者は ですsaeed:saeed
。
なぜこのようなことが起こるのでしょうか?
答え1
ルートとして抽出する場合、tar
デフォルトでは元の所有者 ID が保持されます。ユーザーは、他のコンピュータsaeed
と同じ ID を持っていますubuntu
(おそらく です)。 を実行するか、または現在のユーザーをチェックして1000
ID を確認できます。id saeed
id
ユーザーIDを保存したくない場合は、ルートとして抽出しないか、--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.