Home  >  Article  >  Operation and Maintenance  >  What does linux su password mean?

What does linux su password mean?

青灯夜游
青灯夜游Original
2023-03-20 10:26:167029browse

The password of su is the password of the root user; when installing a Linux or Unix operating system, the user will be prompted to enter the password of root. This is also the password that the user will enter after executing the "sudo su" command. . The full name of su is "switch user", which allows the user to temporarily change the login identity. Except for root, the user account and password to be changed must be entered when changing.

What does linux su password mean?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What does the su password mean?

# The password of su is the password of the root user. When installing a Linux or Unix operating system, it will There is a prompt asking you to enter the root password. This is the password that appears after you execute the sudo su command and asks you to enter the password. Note that this password will not display asterisks or other symbols. It will always be blank. Press Enter after completing the input. Just fine.

su command introduction

su (full English spelling: switch user). In Linux, the su command allows users to temporarily change the login identity. Except for root, the user account and password to be changed must be entered when changing.

Usage permissions: All users.

Function:Change the user identity. If the user account is not specified, the default will be changed to root.

Syntax

su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]

Parameter description:

  • -f or --fast does not need to read the startup file (such as csh. cshrc, etc.), only used for csh or tcsh

  • -m -p or --preserve-environment does not change the environment variables when executing su

  • -c command or --command=command Change to the user whose account is USER and execute the command (command) and then change back to the original user

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

  • --help display description file

  • --version Display version information

  • - -l or --login After adding this parameter, it will be like logging in again for this use Like the user, most environment variables (HOME SHELL USER, etc.) are based on the user (USER), and the working directory will also change. If USER is not specified, the default is root

  • USER User account to be changed

  • ARG Pass in new shell parameters

Common examples :

Example 1: Change the account to root and exit back to the original user after executing the ls command

Command: su -c ls root

 Change the account to root and exit back to the original user after executing the ls command.

[root@localhost ~]# su -c ls root
公共  视频  文档  音乐	anaconda-ks.cfg
模板  图片  下载  桌面	initial-setup-ks.cfg

Example 2: Switch user

Command: su root

Switching testuser to root is equivalent to changing the user to Root but operating in the testuser environment
 Switching between small permissions and large permissions requires entering a password; switching between large permissions and small permissions does not require entering a password.
 Switching users can only obtain the user's execution permissions, but not environment variables.

[testuser@localhost ~]$ whoami //显示当前用户
testuser
[testuser@localhost ~]$ pwd //显示当前目录
/home/testuser
[testuser@localhost ~]$ su root //切换到root用户
密码:
[root@localhost testuser]# whoami
root
[root@localhost testuser]# pwd
/home/testuser

Example 3: Switch users and change environment variables

Command: su - root

  Switch testuser to root, It is equivalent to changing the user to root and operating in the root environment. That is, change the account to root and change the working directory to root's home directory.
 Switch to the user and obtain the user's environment variables and execution permissions.

[testuser@localhost ~]$ whoami
testuser
[testuser@localhost ~]$ pwd
/home/testuser
[testuser@localhost ~]$ su - root
密码:
[root@localhost ~]# whoami
root
[root@localhost ~]# pwd
/root

The difference between su and su -

Note that when using the su command, there is a completely different difference between - and without - option. It means that when switching user identities, even the currently used environment variables are also switched to those of the specified user. We know that environment variables are used to define the operating system environment. Therefore, if the system environment does not switch with the user's identity, many commands cannot be executed correctly.

For example, the ordinary user lamp switches to the root user through the su command, but does not use the - option. In this case, although it appears to be the root user, the $PATH environment variable in the system is still lamp's. (rather than root), so the current working environment does not include the saving paths of superuser commands such as /sbin, /usr/sbin, etc., which makes many administrator commands unable to be used at all. Not only that, when the root user accepts mail, he will find that the mail received is from the lamp user, because the environment variable $MAIL has not been switched.

Beginners can understand the difference between them in this way, that is, with the - option, switching the user identity is more complete; on the contrary, only a part of it is switched, which will cause problems or errors in running certain commands ( For example, the service command cannot be used).

Through the following example, you can intuitively see the difference between su and su -:

[lamp@localhost ~]$ whoami
lamp
#查询用户身份,我是lamp
[lamp@localhost ~]$ su root
密码:
<-输入root密码
#切换到root,但是没有切换环境变量。注意:普通用户切换到root需要密码
[root@localhost ~]# env | grep lamp
#查看环境变量,提取包含lamp的行
USER=lamp
#用户名还是lamp,而不是root
PATH=/usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lamp/bin
#命令査找的路径不包含超级用户路径
MAIL=/var/spool/mail/lamp
PWD=/home/lamp
LOGNAME=lamp
#邮箱、主目录、目前用户名还是lamp

You can see that without using su -, although the user identity is successful Switch, but the environment variables are still those of the original user, and the switch is incomplete.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What does linux su password mean?. 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