The methods to switch user names in Linux systems are: use the su command to switch to the specified user. Use the sudo command to run the command as another user. Enter the user name directly. If the current user has granted switching permission, you can switch directly.
How to switch Linux username
Switching username in Linux system is a simple process, you can This is done by:
Method 1: su command
##su command allows you to switch to another user. The syntax is as follows:
<code>su [用户名]</code>
<code>su john</code>
Method 2: sudo command
# The ##sudo command allows you to run commands as another user. The syntax is as follows: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code>sudo -u [用户名] [命令]</code></pre><div class="contentsignin">Copy after login</div></div>
For example, to run a command as user "john", you can use the following command:
<code>sudo -u john command</code>
In some cases, you can switch directly to another user without using a command. Just enter the following command:
<code>username</code>
For example, to switch to user "john", just enter the following command:
<code>john</code>
Switching to another user requires the user's password.
Direct switching only applies when the current user has been granted permission to switch to the target user. The above is the detailed content of How to switch username in linux. For more information, please follow other related articles on the PHP Chinese website!