Changing users with the su command
As we have entered a multi-user system, it is logical to think that we will be able to change between users. Even when this can be done easily by opening a session for each, sometimes we want to act as several users within one session.
To do so, we can use the su
tool. The name of the tool is usually referred to as Substitute User.
Let’s use that last session, in which we logged in as root
, and turn ourselves into user
.
Before doing so, we can always ask which user we are logged in as by running the whoami
command:
[@rhel-instance ~]# whoami root
Now, we can make the change from root
to user
:
[root@rhel-instance ~]# su user [user@rhel-instance root]$ whoami user
Now, we have a session as user
. We can finish this session by using the exit
command:
[user@rhel-instance root]$ exit exit [root@rhel-instance ~]# whoami root
As you may have seen, when we are logged in as root
, we can act as any user without knowing its password...