The “su” command in Linux is used to switch to another user account, typically the superuser or root account. It allows you to execute commands or run a shell with the privileges of the specified user.
Here is the basic syntax of the “su” command:
su [options] [username]
Here’s a practical example of how to use the “su” command:
- Switch to the root user:
Running the “su” command without specifying a username will switch to the root user account. You will be prompted to enter the root password.
$ su Password:
In this example, executing the “su” command without a username prompts for the root password. Upon entering the correct password, you will switch to the root user and gain root privileges.
- Switch to another user:
Replace “username” with the actual username of the user you want to switch to. This command will prompt you to enter the password of the specified user.
$ su john Password:
In this example, the “su” command is used to switch to the user account “john”. After entering the password for the “john” user, you will switch to that user’s account and gain their privileges.
Note that the “su” command requires appropriate permissions and the knowledge of the target user’s password. It is commonly used by system administrators to perform administrative tasks that require elevated privileges. When you are done with the administrative tasks, it is recommended to exit the superuser or switched user account by typing “exit” or pressing Ctrl+D to return to your original user account.
Exercise caution while using the “su” command, as it grants significant privileges and allows access to sensitive system resources.