Users in CentOS
Introduction
su
The difference between su and su -l
First let's check the $USER variable as a regular user
[andrei@host113 ~]$ echo $USER
andrei
The expected result. Now let's run su and check what happens to $USER
[andrei@host113 ~]$ su
Password:
[root@host113 andrei]# echo $USER
andrei
[root@host113 andrei]# pwd
/home/andrei
$USER is still andrei, and the current directory is andrei's home directory
Let's log in again using su -l (or simply su -)
[root@host113 andrei]# exit
exit
[andrei@host113 ~]$ su -l
Password:
Last login: Mon Sep 13 10:35:05 EEST 2021 on pts/0
[root@host113 ~]# echo $USER
root
[root@host113 ~]# pwd
/root
Now both the user and the current directory have changed.
Logging in
Article author: Andrei Olegovich