Can I print the username which is obtaining root access via su -
on the root console upon obtaining root?
user1$ su -
password:
obtained root via user1
#
Can I print the username which is obtaining root access via su -
on the root console upon obtaining root?
user1$ su -
password:
obtained root via user1
#
Previously I recommend the script below... I found a better way! :) Just exec:
Also, you can use
$SUDO_USER
, but doesn't work if you are usingsudo su -
By the way,
who am i
is likewho -m
This script also does the work:
Call it through
.bash_profile
if you are using login shells or.bashrc
if using interactive non-login shells.who am i|awk '{print "Obtained root via "$1}'
Add it to root's
.bashrc
to execute when yousu
.You can also try
pstree -p -u |grep "$$"
to see the whole chain of processes with usernames. This could be useful if you have nested
su
with multiple users.