Esta es mi topología:
My laptop ==> Ubuntu Desktop
| | |
User: root & saeed
My server ==> Ubuntu 20.04
| | |
Users: root & ubuntu (I deleted it as I explain below)
Los pasos:
- Lo ejecuto
tar zvcf back.tar.gz .
en mi computadora portátil con el usuariosaeed
y se crea el archivo. - Subo este archivo a través de SFTP a mi servidor usando
root
el ejemplo de usuario en la ruta/home/test
, que no es el directorio de inicio de ningún usuario. - Extraigo pero veo que todos los propietarios de archivos y directorios
back.tar.gz
son ./home/test
ubuntu:ubuntu
- Eliminé
ubuntu
el usuario e intenté el tercer paso pero obtuve el mismo resultado. - Lo extraje
back.tar.gz
en mi computadora portátil en otra ruta, pero los propietarios de todos los archivos sonsaeed:saeed
.
¿Por qué pasó esto?
Respuesta1
Al extraer como root, tar
de forma predeterminada se conserva el ID del propietario original. Resulta que el usuario saeed
tiene la misma ID que ubuntu
en la otra computadora (y probablemente sea 1000
). Puede verificar las ID ejecutando id saeed
o simplemente id
verificar el usuario actual.
Si no desea conservar la identificación del usuario, no extraiga como root o use la --no-same-owner
opción. Fragmento relevante delmanual:
--no-same-owner
Extract files as yourself (default for ordinary users).
Se puede lograr lo contrario para los usuarios habituales con --same-owner
.
Opciones relacionadas --owner
y --owner-map
que se pueden utilizar al crear un archivo:
--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.