Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to tell tar to unpack the archive and set the uid/gid to a specific one, when you run tar as root (while using chef) ?

Things I already know:

  • I can use -o to extract as root, then chown uid:gid afterwards
  • --owner and --group apparently only work when adding file, not when unpacking

It would be really convenient to be able to specify the owner while unpacking. Is that possible ?

share|improve this question

Oddly enough, you can get closer to what you want using (GNU) cpio with your tar archive. GNU cpio supports tar format files, and provides the -R command line option to set the user and group of extracted files. This option controls the ownership of all files, not specific files.

All this means that you can run, as root, the following command...

cpio -iv -R user1:group1 < /path/to/myarchive.tar

...and it will extract all the files owned by user user1 and group group1.

share|improve this answer

You can run the chef execute resource as a particular user:

execute "tar -xf /path/to/your/tarfile.tar" do
  user "someone"

Execute Resource Documentation

share|improve this answer

Your Answer


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.