Skip to content
Advertisement

How do you find the original user through multiple sudo and su commands?

When running a script via sudo or su I want to get the original user. This should happen regardless of multiple sudo or su runs inside of each other and specifically sudo su -.

Advertisement

Answer

Results:

Use who am i | awk '{print $1}' OR logname as no other methods are guaranteed.

Logged in as self:

JavaScript

Normal sudo:

JavaScript

sudo su – :

JavaScript

sudo su -; su tom :

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement