Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux su command

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge of this "Linux su command how to use" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Linux su command how to use" article.

Linux commonly used command su (English spelling: switch user) command is used to change the identity of another user, in addition to root, you need to type the user's password.

Syntax su [- fmp] [- c command] [- s shell] [--help] [--version] [-] [USER [ARG]] parameter description:

-f or-fast do not need to read startup files (such as csh.cshrc, etc.) and are only used for csh or tcsh

The environment variable is not changed when-m-p or-preserve-environment executes su

-c command or-command=command change to the user with the account number USER and execute the instruction (command) and then change back to the original user

-s shell or-shell=shell specify the shell (bash csh tcsh, etc.) to be executed. The default value is the user (USER) shell in / etc/passwd.

-help display instruction file

-version displays version information

After the parameter-- l or-login is added, it is like re-login to the user. Most of the environment variables (HOME SHELL USER, etc.) are based on the user (USER), and the working directory will also change. If USER is not specified, it will be root.

User account number to be changed by USER

ARG passes in a new shell parameter

The instance changes the account to root and exits to change back to the original user after executing the ls instruction.

Su-c ls root change the account to root and pass the-f parameter to the newly executed shell

Su root-f change the account to clsung and change the working directory to clsung's home directory (home dir)

Su-clsung switching user

Hnlinux@runoob.com:~$ whoami / / Show current user hnlinuxhnlinux@runoob.com:~$ pwd/ / Show current directory / home/hnlinuxhnlinux@runoob.com:~$ su root / / switch to root user password: root@runoob.com:/home/hnlinux# whoamirootroot@runoob.com:/home/hnlinux# pwd/home/hnlinux switch user, change environment variable

Hnlinux@runoob.com:~$ whoami / / Show current user hnlinuxhnlinux@runoob.com:~$ pwd / / Show current directory / home/hnlinuxhnlinux@runoob.com:~$ su-root / / switch to root user password: root@runoob.com:/home/hnlinux# whoamirootroot@runoob.com:/home/hnlinux# pwd / / Show current directory / root is the content of this article on "how to use Linux su commands". I believe you all have some understanding. I hope the content shared by the editor will be helpful to all of you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report