~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI, Writer of Tidbits, and Linux Enthusiast

Permission Denied: Writing to Privileged Locations

Published on

Updated on

Perhaps you’ve tried something like the following:

sudo echo "hi" > /etc/test

Only to receive back an error

bash: /etc/test: Permission denied

This is because the sudo part only applies to the echo command. Bash which is the process that takes the "hi" from the echo standard out and writes it to /etc/test is still under the unprivileged user.

Instead consider the following:

echo "hi" | sudo tee /etc/test

The command tee takes whatever is in standard in, and writes it to the filename specified. Since we applied sudo to the tee command, it now has the necessary permissions to write to a privileged location.


Have any questions or want to chat: Reply via Email

Enjoyed this post?

Published a response to this? :