3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel


Changing users with the su command



Download 1.85 Mb.
View original pdf
Page3/67
Date26.02.2024
Size1.85 Mb.
#63678
1   2   3   4   5   6   7   8   9   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
Changing users with the su command
As we have entered ab 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

Changing users with the su command
63
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. But how can we impersonate root We can do so by running the su command and specifying the root user. In this case, the root user’s password will be requested:
[user@rhel-instance
]$ su root

Password:
[@rhel-instance user whoami
root
As root is the user with the ID 0 and the most important one, when running su without specifying the user we want to turn into, it will default to turning us into root:
[user@rhel-instance
]$ su

Password:
[root@rhel-instance user whoami
root
Each user can define several options in their own environment, such as, for example, their preferred editor. If we want to fully impersonate the other user and take their preferences (orb environment


Download 1.85 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page