Methods to switch users in Linux include: display the current user, use the "su -" command to switch to another user, use the "sudo" command to execute commands with root privileges, or log in directly as the root user.
How to switch Linux users
In Linux systems, switching users can be completed through the following steps:
1. Display the current user
Use the "whoami" command to display the current login username:
<code>$ whoami</code>
2. Switch to other users
Use the "su -" command to switch to another user:
<code>$ su - username</code>
where "username" is the target username to be switched to.
3. Use the sudo command
The sudo command allows ordinary users to execute specified commands with root privileges.
<code>$ sudo command</code>
However, ordinary users need to enter their own password to use sudo.
4. Log in with root privileges
Log in to the system directly with the root user:
<code>$ su</code>
This will enter the root user’s session.
Tip:
The above is the detailed content of How to switch users in linux. For more information, please follow other related articles on the PHP Chinese website!