Home  >  Article  >  System Tutorial  >  What are the commands to switch usernames in Linux?

What are the commands to switch usernames in Linux?

下次还敢
下次还敢Original
2024-04-12 13:03:14553browse

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.

What are the commands to switch usernames in Linux?

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
  • sudo
  • login
  • su -
  • sudo -u

##su Command

## The #su

command is used to switch sessions as another user. Its syntax is as follows: <pre class="brush:php;toolbar:false">&lt;code&gt;su [用户名]&lt;/code&gt;</pre> For example, to switch sessions as user

bob

, enter: <pre class="brush:php;toolbar:false">&lt;code&gt;su bob&lt;/code&gt;</pre>

sudo

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">&lt;code&gt;sudo -u 用户名 命令&lt;/code&gt;</pre>For example, to run the

ls

command as user bob, enter: <pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u bob ls&lt;/code&gt;</pre>

login

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">&lt;code&gt;login 用户名&lt;/code&gt;</pre>For example, to log in as user

bob

, enter: <pre class="brush:php;toolbar:false">&lt;code&gt;login bob&lt;/code&gt;</pre>

su -

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">&lt;code&gt;su - 用户名&lt;/code&gt;</pre>For example, to switch sessions as the login shell of user

bob

, enter: <pre class="brush:php;toolbar:false">&lt;code&gt;su - bob&lt;/code&gt;</pre>

sudo -u

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">&lt;code&gt;sudo -u 用户名&lt;/code&gt;</pre>For example, to run an interactive shell as user

bob

, enter: <pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u bob&lt;/code&gt;</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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn