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경로 예제에서 사용자를 사용하여 SFTP를 통해 이 파일을 내 서버에 업로드합니다 ./home/test
  3. 압축을 풀었 back.tar.gz지만 /home/test모든 파일과 디렉토리의 소유자가 입니다 ubuntu:ubuntu.
  4. 사용자를 삭제 ubuntu하고 세 번째 단계를 시도했지만 동일한 결과를 얻었습니다.
  5. back.tar.gz노트북에서 다른 경로로 압축을 풀었는데 모든 파일의 소유자는 saeed:saeed.

왜 이런 일이 발생합니까?

답변1

루트로 추출하면 tar기본적으로 원래 소유자 ID가 유지됩니다. 사용자는 우연히 다른 컴퓨터 saeed와 동일한 ID를 가지고 있습니다 (아마도 그럴 것입니다 ). 를 실행하여 ID를 확인 하거나, 현재 사용자를 확인하기만 하면 됩니다.ubuntu1000id 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.

관련 정보