summaryrefslogtreecommitdiff
path: root/Executing bash commands as another user.md
diff options
context:
space:
mode:
Diffstat (limited to 'Executing bash commands as another user.md')
-rw-r--r--Executing bash commands as another user.md12
1 files changed, 12 insertions, 0 deletions
diff --git a/Executing bash commands as another user.md b/Executing bash commands as another user.md
new file mode 100644
index 0000000..c934f16
--- /dev/null
+++ b/Executing bash commands as another user.md
@@ -0,0 +1,12 @@
+---
+tags:
+ - bash
+---
+[[Bash]] [[Temporary set permissions with which new files are created]]
+
+Using `sudo` we can execute commands as other users, most commonly as the root user. When passing `-u` switch we can specify different users.
+
+When the command involves output redirection it is common to pass the entire command to a shell executed as that user: `sudo -u user bash -c 'command > redirect'`.
+
+## Why do I get "command not found" as I execute with another user?
+This can be because `sudo` normally discards the environment. Passing the `-i` switch makes sudo "login" which causes `.profile` et al to be sourced, thus configuring the user environment. \ No newline at end of file