Home > System Tutorial > LINUX > body text

What are the commands to switch usernames in Linux?

下次还敢
Release: 2024-04-12 13:03:14
Original
569 people have browsed it

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: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;su [用户名]&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div> For example, to switch sessions as user

bob

, enter: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;su bob&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>

sudo

Command The

sudo

command allows users to execute commands as root or other users. Its syntax is as follows: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u 用户名 命令&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>For example, to run the

ls

command as user bob, enter: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u bob ls&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>

login

Command

login

Command exits the current session and logs in with a new username. Its syntax is as follows: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;login 用户名&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>For example, to log in as user

bob

, enter: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;login bob&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>

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: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;su - 用户名&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>For example, to switch sessions as the login shell of user

bob

, enter: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;su - bob&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>

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: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u 用户名&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>For example, to run an interactive shell as user

bob

, enter: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;code&gt;sudo -u bob&lt;/code&gt;</pre><div class="contentsignin">Copy after login</div></div>

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template