Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    Are you aware that sudo can run commands as any user, not just as root? is that an acceptable solution or do you need this to happen in systems with no sudo installed? Also, what operating system is this about? Commented Jul 21, 2021 at 15:52
  • The question is unclear. What do you want to achieve? If it's just that echo $USER shows a different value, you can set the environment variable USER. This does not change anything about the program's privileges, it just changes the value of the variable. If you actually want to run as a different user, then why not use sudo? What do you call “the correct username”? With multiple users involved, there isn't a single user name. Commented Jul 21, 2021 at 15:59
  • @terdon I'm using Debian 10, sudo is installed and i did not know that the target user would be recorded in the $USER variable when sudo -u username would be used. My goal is to catch the original user using sudo or not using sudo. I guess i need to do some more digging into sudo. Commented Jul 21, 2021 at 16:12
  • @Gilles'SO-stopbeingevil' 'SO- stop being evil' What i mean with correct username is the original user invoking the script whether he's using sudo or not. Commented Jul 21, 2021 at 16:17
  • In the sudo case, do you mean the user who ran sudo or the user that sudo switched to? And either way, what do you want to do with this information? Commented Jul 21, 2021 at 16:24