Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to find out how gzipping a file changes its permissions. The gzip manual (man gzip) says:

Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.

Now, I have a file 'myfile.txt' whose owner is me (myuser). When I gzip this file as another user (that user (say 'otheruser') has read and write permissions in this directory and file), the owner of the gzip file becomes this otheruser. That is, whoever gzip's the file becomes the owner of the .gz file.

Also, whoever gunzip's this file becomes the owner of the uncompressed file. Does this mean gzip does nothing at all about ownerships? If so, what does the above sentence in the manual page mean?

I don't believe the 'Whenever possible' clause might be a problem here since I'm in Unix (Solaris) where permissions retention is (AFAIK) possible.

A related question: if a user has read permission on a .gz file, is it still possible that he cannot read the contents of the file? Does gzip maintain a separate set of permissions 'within' the archive which can limit access? This does not seem probable, but I'd like to be sure.

I need to write code depending on the behaviour of gzip, so finding out the exact behaviour is important for me. Any help would be appreciated.

Thanks.

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Changing file ownership can only be done by root. Ordinary user_a simply cannot create a file owned by ordinary user_b, whether file creation is done by gzipping or by gunzipping. If you need to preserve ownership, unzip as root.

share|improve this answer
add comment

HPUX uses a very old version of gzip (1.3.5 on 11.31 ia64) and it does exactly as the manual page describes. usera can gzip and gunzip a file owned by userb and all permissions and modes are preserved. Root user gzip/gunzip are not needed.

However, for versions 1.4 and above it appears that gzip cannot successfully change the owner/permissions properly unless you are root. In my opinion this is a bug. You can manually go thru the steps to gzip/gunzip a file owned by another user iff you have unix permissions to do so.

$ gzip -c file >file.gz $ chmod NNN file.gz (where NNN is the mode of file) $ chown user:group file (where user:group are the user and group owners of file) $ rm file

Why can't gzip versions >1.4 do this when versions <1.4 do it just fine?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.