Switch user accounts in Linux: Use the su command: used to temporarily switch users and retain the current session. Use sudo command: used to switch users with administrator privileges without retaining the current session.
Use commands to switch user accounts in Linux
In the Linux operating system, you can use the command line to easily switch user account. The two most common methods are introduced below:
Method 1: su command
The su command allows you to temporarily switch to another user. The syntax is as follows:
<code>su [username]</code>
For example:
<code>su bob</code>
This will switch to user "bob" while retaining the current user session.
Method 2: sudo command
The sudo command allows you to execute commands with administrator privileges, including switching users. The syntax is as follows:
<code>sudo -u [username] [command]</code>
For example:
<code>sudo -u bob whoami</code>
This will execute the "whoami" command as user "bob". Note that you need to enter the current user's password to use the sudo command.
Detailed explanation:
su command:
sudo command:
Examples:
Here are some examples of switching users using su and sudo:
<code>su bob</code>
<code>sudo -u bob mkdir new_directory</code>
<code>exit</code>
The above is the detailed content of How to use commands to switch user accounts in Linux. For more information, please follow other related articles on the PHP Chinese website!