Different types of user switch in Linux
In Linux, there are different types of user switches that can be used to change the current user to another user or to gain administrative privileges. User switching is an essential feature in Linux, especially for system administrators, who need to perform various tasks with different user accounts. In this blog post, we will discuss the different types of user switches available in Linux.
su (Switch User)
The su command is used to switch to another user account in Linux. The su command is mostly used to switch to the root user account, which has administrative privileges. The syntax for using the su command is as follows:
If you do not specify a username, the default user is the root user. You will be prompted to enter the password for the user you want to switch to. Once you enter the correct password, you will be logged in as that user.
sudo (Superuser Do)
The sudo command is used to execute a command with administrative privileges. The sudo command allows a user to execute a command with the privileges of the root user without actually logging in as the root user. The syntax for using the sudo command is as follows:
You will be prompted to enter your password to authenticate yourself. Once you enter the correct password, the command will be executed with administrative privileges.
1. Switching users with login shell
su - username
The login shell reads the configuration files in the following order:
2. Switching users with non-login shell
The non-login shell reads the configuration files in the following order:
Appendix: Bash Configuration Files
- Profile configuration: sets environment variables, executes commands or scripts automatically after login
- Bashrc configuration: sets local variables, sets aliases
Small world. Big idea!
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- No personal information is collected
- Made with Material for MkDocs and generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @
- Get latest SRE news and discuss on Discord Channel