[Linux programming] Three minutes let you learn to change user passwords under Linux

There are two types of password changes in the Linux environment:
the first type: rootuser (administrator) password change
The second type: 非rootuser (ordinary user) password change

Scenarios that may require a password change:

①After purchasing the cloud service, the original root password is too complicated to memorize and use, and the root password needs to be changed.
②After creating a new user, I found that the password originally set was not easy to manage, or I shared this account with others before, but I wanted to withdraw the account.
③ Nothing to do, just play~


1. Change the root user password

General idea: To change the root password, it must be done under the root user.

Step 1: Preliminary preparation, log in to the root user
We can log in directly with the root user, enter the user name and password to log in.
insert image description here
insert image description here
If we log in with a non-root user (other than root):
insert image description here
insert image description here
we need to switch the non-root user to the root user first, because the root user password can only be changed under the root user. This is a kind of user authority management. The root user has the highest authority, and ordinary users do not have that high authority.

Requires su command for user switching
insert image description here

Note:
1) Supplementary use of the su command:
①The non-root user can switch to the root user and use the su command directly (that is, su directly adds the Enter key to enter)
②The root user needs to use the su command plus the user name to switch to the non-root user (You need to tell the system which non-root user you want to switch to! There is only one root user, and there can be multiple non-root users), that is, su username (note that commands and parameters need to be separated by spaces, so that Difference, as for whether you use one space or multiple spaces, it has no effect)
2) Password input:
①Non-root user --> root user needs to enter a password; root user --> non-root user may not need a password
②When When we use the keyboard to enter the password, nothing is displayed on the screen. (Not like Windows displays * *** or other characters) but we have actually entered it.
③ When the password is entered, press the Enter key. If the password is correct, the switch is successful. Otherwise, you will be prompted to enter the wrong password and re-enter it. .

Step 2: Use the passwd command to change the password
Introduction to the passwd command: passwd is the abbreviated form of password, which is used to change the password. The common parameters (you can understand the following content)
insert image description here
are as follows:
insert image description here

①Enter passwd directly, then press Enter ②At
this time, the system will prompt us to enter the new password New password, just enter it directly
③The system will prompt us to re-enter the new password to confirm Retype new password, and then enter it again
④If the steps ② and ③ enter the same password, then the password change is successful, otherwise you need to re-operate.


First, non-root user password change

There are two ways to change the password of a non-root user, one is to change it with the root user, and the other is to change it with a non-root user.

Method 1: Use the root user to change the password
insert image description here
Use passwd username directly (username represents the username to be changed), then enter the new password, confirm the new password, and the change is successful...

Note: When using the root user to change a non-root user, there is no need to enter the password of the non-root user itself. The root user can really "do whatever they want".

Method 2: Use a non-root user to change the password
insert image description here
To change the password of a user, log in to the corresponding user.

Don't log in to another user, think about if other users can also change our password, then what's the point of our password, just to log in formally? .
If a big devil appears one day and changes the passwords of all users, is it that everyone can't log in? Some students may raise a bar and say, "Can you also change the passwords of all non-root users with the root user? ?".
Then we can't "don't tell the big devil the root password?" Don't even tell anyone but the administrator the root password to ensure security for all users.

Guess you like

Origin blog.csdn.net/QIYICat/article/details/123013548