Once sudo su'd to root, is there a command to see my username?
The shell's parent process is su -
, and the parent of that is the sudo su -
. So you need to find out the user running sudo su -
's parent process by searching back in two steps with ps
:
ps -o user= $(ps -o ppid= $(ps -o ppid= $PPID))
But you shouldn't be doing sudo su -
if your version of sudo is not too old to have sudo -i
. Sudo sets the environment variable SUDO_USER
to the name of the user who ran sudo. You won't see it with sudo su -
because su -
scrubs the environment.
$ sudo -i
# echo $SUDO_USER
gilles
Run command whoami
it will return you something like that:
gladimdim tty2 2011-01-27 23:54 (:0)
In bold "gladimdim" is the user which was initially logged to system.