Switch users with su
User Privileges in Shell Environments
Overview of Root User Access
There are two methods to operate as a root user: the Old Way and the New Way.
Emphasis on using the Old Way mainly in RADEL 10 for switching user accounts in a shell environment.
Old Way: Using su Command
The
sucommand (short for substitute user) allows one to switch to another user account.Syntax:
su - <target-user>
Environment Variables
Utilizing
suwith the minus (-) option:Example:
su - <target-user>enables loading the complete environment of the target user.Importance: Ensures that all environment variables are set appropriately.
Password Requirement
When executing
su, a password for the target user is required for access.If switching to root user is needed, and the root has a password set,
su -can be used with the root password.Note: Using
su -with the root user's password is generally considered bad practice.
New Way: Using sudo Command
A more secure method to execute commands as a different user, typically as root, without switching the shell environment.
Preferred Command:
sudo -i(where-istands for interactive mode).
Advantages of sudo -i
Prompts for the user's own password instead of the root password, enhancing security.
This approach prevents unnecessary exposure of the root user password.
Scope of Permissions
In a
sudo -ienvironment, the user does not possess full root privileges throughout the entire environment.Avoid using
whoamifor privilege escalation or managing tasks as root in this context.Use
whoamiprimarily for testing different user accounts' permissions, as is discussed later in the context of permissions.