Why sudoing twice shows unexpected values for USER, USERNAME and LOGNAME environment variables
Issue
-
When sudoing twice, USER, USERNAME and LOGNAME environment variables contain
root
instead of the user we are logged in# sudo sudo -u testuser bash -c 'echo "LOGNAME=$LOGNAME; USER=$USER; USERNAME=$USERNAME"' LOGNAME=root; USER=root; USERNAME=root
-
When sudoing only once, USER, USERNAME and LOGNAME environment variables contain the login of the user we are logged in
# sudo -u testuser bash -c 'echo "LOGNAME=$LOGNAME; USER=$USER; USERNAME=$USERNAME"' LOGNAME=testuser; USER=testuser; USERNAME=testuser
Environment
- Red Hat Enterprise Linux 7.5 and later
- sudo >= 1.8.19p2-10
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.