The USER env variable is unchanged after gaining root access.
[user1@comp]$ echo $USER
user1
Logged in the system as 'user1'. Now check the output after gaining root access.
[user1@comp]$ su
Password:
[root@comp]# echo $USER
user1
If I were to login as 'root' user, then USER env is set to 'root'. There is no issue there. This behavior was observed in Fedora and CentOS. Why is the env variable not updated?
$USER
env variable often doesnt get updated when you switch to root, you can trywhoami
or some other alternative like , I have readwho am i
works for some people too (but not for me on Ubuntu) – the_velour_fog Jan 28 '16 at 6:02