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 other users in the same session we are in.
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 the user
user.
Before doing so, we can always ask which user I am logged in with by running the whoami
command:
[root@rhel8 ~]# whoami root
Now we can make the change from root
to user
:
[root@rhel8 ~]# su user [user@rhel8 root]$ whoami user
Now we have a session as the user
user. We could finish this session by using the exit
command:
[user@rhel8 root]$ exit exit [root@rhel8 ~]# whoami root
As you may have seen, when we are logged in as root
, we can act as any user without knowing its password. But...