From 0d389e1d6c1aed4a92f82d9711f4564a12390fcd Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Mon, 16 Jun 2025 10:44:49 +0200 Subject: vault backup: 2025-06-16 10:44:49 --- Executing bash commands as another user.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Executing bash commands as another user.md (limited to 'Executing bash commands as another user.md') 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 -- cgit v1.2.3