What does linux su password mean?

Mar 20, 2023 am 10:26 AM
linux

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]]
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles