2

I know this question has been covered in many contexts but I'm unable to understand and predict when a user added to the sudoers file will not have permission to do something when prepending sudo to a command.

ubuntu@localhost$ ls -lh
-rw-r--r-- 1 root   root     10 Aug 11 11:21 test
ubuntu@localhost$ sudo echo 'something' >> test
-bash: test: Permission denied

ubuntu@localhost$ sudo su
root@localhost# echo 'something' >> test

Why am I denied permission to execute the command sudo echo 'something' >> test?

2

In this particular case, it's because echo is the command with superuser powers. The >> part has normal privileges. If you want to write with sudo powers, use

$ echo 'something' | sudo tee test

Hence, in your case, the former version is not exactly running as sudo in its entirety. That is what the difference is here. Nevertheless, there are some actual differences between sudo and logging in as root too, I think, involving environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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