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て3番目の手順を試しましたが、同じ結果になりました。
  5. back.tar.gzラップトップの別のパスに解凍しましたが、すべてのファイルの所有者は ですsaeed:saeed

なぜこのようなことが起こるのでしょうか?

答え1

ルートとして抽出する場合、tarデフォルトでは元の所有者 ID が保持されます。ユーザーは、他のコンピュータsaeedと同じ ID を持っていますubuntu(おそらく です)。 を実行するか、または現在のユーザーをチェックして1000ID を確認できます。id saeedid

ユーザー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.

関連情報