diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-06-16 10:44:49 +0200 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-06-16 10:44:49 +0200 |
commit | 0d389e1d6c1aed4a92f82d9711f4564a12390fcd (patch) | |
tree | ca4925547669a045d836c2aeb6d4b2309c3f5996 /Executing bash commands as another user.md | |
parent | 32422d2b9001291d7136036581122cf4b4eec75c (diff) |
vault backup: 2025-06-16 10:44:49
Diffstat (limited to 'Executing bash commands as another user.md')
-rw-r--r-- | Executing bash commands as another user.md | 12 |
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 |