Saturday, April 27, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 590  / 3 Years ago, fri, may 7, 2021, 6:42:50

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.


More From » command-line

 Answers
6

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)


[#34303] Saturday, May 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ularousand

Total Points: 380
Total Questions: 109
Total Answers: 101

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;