Home > Article > System Tutorial > What are the commands to switch usernames in Linux?
The commands to switch Linux user names are: su command, which is used to switch sessions as another user. The sudo command is used to execute commands as the root user or other users. login command, used to log out of the current session and log in with a new username. su - Command to switch sessions as another user's login shell. The sudo -u command is used to run an interactive shell with the specified username.
Linux command to switch user name
In the Linux operating system, there are a variety of commands that can be used to switch users name. These commands include:
##su Command
## The #su command is used to switch sessions as another user. Its syntax is as follows: <pre class="brush:php;toolbar:false"><code>su [用户名]</code></pre>
For example, to switch sessions as user
, enter: <pre class="brush:php;toolbar:false"><code>su bob</code></pre>
Command The
sudo command allows users to execute commands as root or other users. Its syntax is as follows: <pre class="brush:php;toolbar:false"><code>sudo -u 用户名 命令</code></pre>
For example, to run the
command as user bob
, enter: <pre class="brush:php;toolbar:false"><code>sudo -u bob ls</code></pre>
Command
login Command exits the current session and logs in with a new username. Its syntax is as follows: <pre class="brush:php;toolbar:false"><code>login 用户名</code></pre>
For example, to log in as user
, enter: <pre class="brush:php;toolbar:false"><code>login bob</code></pre>
Command The
su - command switches sessions with another user's login shell, which means it sets new environment variables and loads the user's configuration file. Its syntax is as follows: <pre class="brush:php;toolbar:false"><code>su - 用户名</code></pre>
For example, to switch sessions as the login shell of user
, enter: <pre class="brush:php;toolbar:false"><code>su - bob</code></pre>
Command
sudo -u The command is similar to the sudo
command, but it allows the user to run an interactive shell under a specified username. Its syntax is as follows: <pre class="brush:php;toolbar:false"><code>sudo -u 用户名</code></pre>
For example, to run an interactive shell as user
, enter: <pre class="brush:php;toolbar:false"><code>sudo -u bob</code></pre>
The above is the detailed content of What are the commands to switch usernames in Linux?. For more information, please follow other related articles on the PHP Chinese website!