Home > Article > Computer Tutorials > How to switch users in Linux system?
Linux is a multi-user, multi-tasking, multi-threading and multi-CPU operating system based on POSIX and Unix. It supports multiple users to log in and operate at the same time, so in Linux Switching users is one of the very common operations. So how to switch users in Linux system? The following is an introduction to common commands.
1.su command
su command is a common command used to switch users. Through the su command, you can switch to other user accounts in the terminal and perform corresponding operations. When using the su command, you need to provide the credentials of the target user account, usually the password. For example, to switch to the root user, enter the su command in the terminal and enter the root user's password. The use of the su command helps to perform tasks as different users in the system and improve operation permissions.
”’shell
su – root
”’
This command will prompt you to enter the password of the root user. After entering the correct password, you can execute the command under the root user.
2. sudo command
The sudo command allows ordinary users to run specific commands with superuser privileges and is usually used for operations that require administrator privileges. When using sudo in the terminal, the user is asked to enter their own password to confirm authentication. For example, when executing commands that require root privileges, you can use the sudo command to elevate privileges.
”’shell
sudo command
”’
This command will prompt you to enter the password of the current user. After entering the correct password, you can execute the command with the permissions of the root user.
3. su -l command
The -l option of the su command can switch to the specified user account and switch the environment variables to the environment variables of the specified user. Enter the following command in the terminal to switch users:
”’shell
su -l username
”’
Where username is the user account to be switched to. This command will prompt for the password of the specified user. After entering the correct password, you can execute the command under that user.
4. Login command
The login command is used to switch users and log in to the system again. When using the login command, you need to enter the user account and password you want to switch to. For example, enter the following command in the terminal to switch users:
”’shell
login
”’
This command will prompt you to enter the user account and password to switch to. After entering the correct account and password, the system will log in as the user again.
The above is the detailed content of How to switch users in Linux system?. For more information, please follow other related articles on the PHP Chinese website!