Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On Ubuntu, in what kind of situations, if any, running a command as a non-root to access a file/folder or create/delete a file/folder using sudo may result in "permission denied" while running the same command as root user would succeed? The user is assumed to be a sudoer, of course.

Practical example on Ubuntu 12: I've got this directory in / with root:root ownership and drwxr-xr-x permissions and I tried sudo date > file while in it as well as sudo date | tee file but got the same

-bash: file: Permission denied

in both cases. Sure enough, there're no problems if I'm root. This is quite frustrating.

share|improve this question
    
Yes, it would succeed. –  Hckr Nov 13 '12 at 22:59
    
Running commands on a file without sudo depends on the permissions of the file, whether you're an owner of that file, belong to a group that has permissions for that file, etc. It also depends on what you're doing with it such as viewing, modifying, moving, deleting, running, etc. To see the permissions of a file you have access to in Nautilus, right click it and select Properties, then the Permissions tab. To read about file permissions, see askubuntu.com/questions/83/how-do-file-permissions-work. –  James Nov 13 '12 at 23:09
    
Does the file to which you pipe have the immutable bit set? See secure.wikimedia.org/wikipedia/en/wiki/Chattr –  0xC0000022L Nov 14 '12 at 0:17
add comment

2 Answers

up vote 4 down vote accepted

What's the command you are trying? A common mistake is sudo foo > output which doesn't run the output redirection as root because it's done by the shell. A solution to this one would be foo | sudo tee output (or sudo foo | sudo tee output if foo requires root access)

share|improve this answer
    
My bad, I edited the answer now to have the correct commands –  Dennis Kaarsemaker Nov 13 '12 at 23:29
add comment

sudo lets you run a program as another user - as root by default.

It's the same as if root runs that program (except maybe for some environment variables and such). So there is no such situation.

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.