mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-25 09:36:31 -05:00
851 B
851 B
date | draft | math | medium_enabled | medium_post_id | tags | title |
---|---|---|---|---|---|---|
2022-04-07 20:09:40-04:00 | false | false | true | 7d133254be3f | Permission Denied: Writing to Privileged Locations |
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.