What are the commands for switching users in Linux?

  Linux is an open source operating system with multi-user features, that is, it supports multiple users to log in and operate at the same time. In Linux, the command to switch users is very important. It allows users to switch to other users and perform different operations without exiting the current user. The following are the details:

  The commands for switching users in Linux mainly include the following:

  1. su command

  The su command is the most common switch user command. It can switch to another user account and let you continue working under this user account. When using the su command, you need to enter the user account and password to switch to. For example, to switch to the root user, enter the following command in the terminal:

  ```shell

  su - root

  ```

  This command will prompt you to enter the password of the root user. After entering the correct password, you can execute commands under the root user.

  2. sudo command

  The sudo command allows ordinary users to execute commands as superusers. It is usually used when normal users need to execute commands that require administrator privileges. When using the sudo command, you need to enter your own password. For example, to execute a command as root, enter the following command in Terminal:

  ```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 root user privileges.

  3. su -l command

  The -l option of the su command can switch to the specified user account, and switch the environment variable to the environment variable 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 you to enter the password of the specified user. After entering the correct password, you can execute commands under this 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 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 be switched to. After entering the correct account and password, the system will log in as the user again.

  5. su -s command

  The -s option of the su command can switch to a specified user and specify a shell program as the default shell program after switching. Enter the following command in the terminal to switch users:

  ```shell

  su -s shell_program username

  ```

  Among them, shell_program is the program name to be used as the default shell program after switching, and username is the user account to be switched to. This command will prompt you to enter the password of the specified user. After entering the correct password, you can execute commands under this user.

  To sum up, the commands for switching users in Linux mainly include su, sudo, su -l, login and su -s, etc. Through these commands, users can switch to other users and perform operations with different permissions without exiting the current user.

Guess you like

Origin blog.csdn.net/oldboyedu1/article/details/132279657