Permssions for Files in Tar files

Discuss Applications
Post Reply
agent007
administrator
administrator
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Permssions for Files in Tar files

Post by agent007 » Mon Feb 24, 2003 3:48 am

Hi all,

Sometimes when I extract the tar files, the extracted files seem to be belonging to someone else in terms of permissions..Would it be better if I change the permissions to 'root'?
Also, how do the files retain the permissions of someone else? I mean, after I extract the tar on my system, the permissions should automatically change to 'root' correct?

thanks,
007

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Feb 24, 2003 4:11 am

If you extract an archive under root's ID, by default it will try and recreate the same ownership and permissions of the original files. If you received this archive from someone else then the chances that you both have all the same usernames on your systems are small. If the name doesn't exist it will use the user number. If the user number belongs to someone else on your system the files will be owned by that someone else. If that user number does not exist in /etc/passwd then you will see only a number and not a name associated with the files that are extracted.

Now if you extract the archive under a normal user account then all files contained within the archive should take on the owner/group names of the user that extracted them. Normal users do not have permission to create a file with someone other than that user owning the file, would be a huge security problem.

There are some options where you can control how permissions are restored:

http://www.gnu.org/manual/tar/html_node/tar_122.html

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Mon Feb 24, 2003 9:15 am

i came across this last night actually, i did a 'tar -cvzf backupfeb03.tar.gz /home' and when i untarred it, i was delighted to see that all the permissions and ownerships were the same as they had originally been! that has a big benefit over burning the lot to a CD as a directory structure. plus it ended up less than half the size too.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Feb 24, 2003 9:17 am

Yes, I would say tar is probably THE most used backup utility. It wouldn't be much of a backup utility if it couldn't restore proper file permissions.

agent007
administrator
administrator
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Post by agent007 » Tue Feb 25, 2003 1:52 am

hi!

VoidMain, thanks for the detailed info... :D Btw, what about dd? Isin't it better than tar for backup purposes?

thanks,
007

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Feb 25, 2003 1:59 am

dd and tar are two different concepts, both useful and both can be used together or separately. I assume you are asking why not just do a "dd if=/dev/hda1 of=/dev/tape bs=32k" etc. Ok, fair enough, now what if you want to just extract a single file from that dd dump on tape rather than restore your entire partition? Remember, a *major* component of backups are restore capabilities.

Of course there are many other backup solutions both free and proprietary but tar is probably still the most widely used at the base of most backup strategies.

agent007
administrator
administrator
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Post by agent007 » Tue Feb 25, 2003 3:52 am

Yeah, someone gave me the tar file and when I extracted it (in root) guess it found the User number and the files *belonged* to someone else....I wonder if this is a good feature..I mean by default why should it restore the permissions? ( even though in case of backups it maybe a plus point, but thats a different case alltogether)

thanks,
007


Void Main wrote:If you extract an archive under root's ID, by default it will try and recreate the same ownership and permissions of the original files. If you received this archive from someone else then the chances that you both have all the same usernames on your systems are small. If the name doesn't exist it will use the user number. If the user number belongs to someone else on your system the files will be owned by that someone else. If that user number does not exist in /etc/passwd then you will see only a number and not a name associated with the files that are extracted.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Feb 25, 2003 3:58 am

agent007 wrote:Yeah, someone gave me the tar file and when I extracted it (in root) guess it found the User number and the files *belonged* to someone else....I wonder if this is a good feature..I mean by default why should it restore the permissions? ( even though in case of backups it maybe a plus point, but thats a different case alltogether)
As I mentioned. Don't extract archives as root if you don't want permissions to be restored. I rarely extract tar archives as root. There are other reasons for not extracting tar archives as root, as well as the general rule of thumb of not being root unless you absolutely have to. That reason is if the person that created the archive included leading slashes "/" then you could overwrite key system files if you are not careful. For instance, if you have an archive that includes the file "/etc/passwd" instead of "etc/passwd" or "./etc/passwd" then you will overwrite your real /etc/passwd when you extract it if you are root and do not take special precautions.

I believe it is a good default to extract permissions. I don't like an OS that babies me, takes too long to get stuff done.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Tue Feb 25, 2003 8:34 am

sounds like there are many positives of retaining permissions and no negatives except those that carelessness would bring about.

Post Reply