mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-12-22 23:42:30 +00:00
New Post
This commit is contained in:
parent
57af71b063
commit
63ea2d6124
1 changed files with 29 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
title: "Permission Denied: Writing to Privileged Locations"
|
||||
date: 2022-04-07T20:09:40-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
math: false
|
||||
---
|
||||
|
||||
Perhaps you've tried something like the following:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
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.
|
Loading…
Reference in a new issue