I would like to tar an directory with a non-root user. But in this directory are also files with root permissions.


foo@bar:~ $ ls -l tmp/
insgesamt 8
-rw-r--r-- 1 foo  foo  6 Mär 16 08:38 test.1
-rw------- 1 root root 6 Mär 16 08:38 test.2

If I run tar-command as "foo" user, I received an error: "Permission denied". Example:

foo@bar:~ $ tar -czf --preserve-permissions test.tar.gz ./tmp
tar: tmp/test.2: function open failed. Permission denied.

How can I solve this permission issue? If possible, I prefer do use a non-root user.

  • 1
    If you could, you would have found a serious security bug in Linux ...
    – pLumo
    Mar 16, 2021 at 7:57
  • I thought so. ;)
    – Qaldak
    Mar 16, 2021 at 8:01

1 Answer 1


You can not.

To tar a file, you need to read it. However, only root is allowed to read and write the file. (permissions are rw------- / 600).

owner = rw-
group = ---
others = ---

Owner is root, foo is likely others.

You could read the file with user foo after changing permissions:

# give read permission (+r) to others (o) 
sudo chmod o+r ./tmp/test.2


# Set specific permissions value -> 6=rw- 4=r--
sudo chmod 644 ./tmp/test.2

or by changing owner to foo:

sudo chown foo: ./tmp/test.2

If your user is not a sudoer on that machine, you could still do this from a root console or from a live system.

Then, your command should work fine without problems:

foo@bar:~ $ tar -czf --preserve-permissions test.tar.gz ./tmp

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .