[xubuntu-users] Detecting login name after su

Kevin O'Gorman kogorman at gmail.com
Fri Oct 4 19:10:49 UTC 2013

On Fri, Oct 4, 2013 at 6:12 AM, ABIX Adam Jurkiewicz
<a.jurkiewicz at abix.info.pl> wrote:
> Dnia 2013-10-03, czw o godzinie 20:14 +0100, Peter Flynn pisze:
>> Does anyone know how a bash script can detect what username you
> just grep your environment:
> adasiek at adasiek-ThinkPad-T410:~/Dokumenty$ sudo -i
> [sudo] password for adasiek:
> root at adasiek-ThinkPad-T410:~# env | grep SUDO
> SUDO_USER=adasiek
> SUDO_UID=1000
> SUDO_COMMAND=/bin/bash
> SUDO_GID=1000

That looked interesting so I tried it.  It works as you showed, but
the OP also mentioned another way in, where it does not work:

kevin at treat:~$ sudo su -
root at treat:~# env | grep SUDO
root at treat:~# env | wc -l
root at treat:~# env | grep kevin
root at treat:~#

And indeed the environment in that was is quite impoverished,
containing just 20 lines, mostly very familiar.  LOGNAME was root. The
only one with a hint of the original account is XAUTHORITY, and I have
no idea how reliable that is.

Kevin O'Gorman

programmer, n. an organism that transmutes caffeine into software.
Please consider the environment before printing this email.

More information about the xubuntu-users mailing list