Bootstrap

linux中更改用户密码_如何在Linux中更改用户密码

linux中更改用户密码

In this tutorial, we will focus on how you can change a user’s password in Linux. We will delve deeper and see how to force a user to change their password the next time they try logging in. These commands are standard and will work for any Linux distribution.

在本教程中,我们将重点介绍如何在Linux中更改用户密码。 我们将进行更深入的研究,并了解如何在用户下次尝试登录时强制其更改密码。这些命令是标准命令,适用于任何Linux发行版。

Let’s jump right in.

让我们跳进去。

1.更改您的用户密码 (1. Changing your user password)

As a regular user in a Linux system, you can only change your password. The root user is the only user that can change the passwords of other users.

作为Linux系统的普通用户,您只能更改密码。 root用户是唯一可以更改其他用户密码的用户。

The command used for changing users’ password is the passwd command. It is usually followed by the username of the user whose password you want to change i.e.

用于更改用户密码的命令是passwd命令。 通常,其后是要更改其密码的用户的用户名,即

# passwd your_username

For example, if you want to change the password of a user jamie, execute

例如,如果要更改用户jamie的密码,请执行

# passwd jamie

You will be prompted to type your current password and later provide the NEW password and confirm it.

系统将提示您输入当前密码,然后提供新密码并进行确认。

Sample Output

样本输出

When providing a new password , ensure that you use a STRONG and UNIQUE password. A strong password should have the following.

提供新密码时,请确保使用STRONG密码和UNIQUE密码。 强密码应具有以下内容。

  1. It should have a combination of Uppercase, Lowercase, Numeric and Special characters

    它应包含大写,小写,数字和特殊字符的组合
  2. It should have more than 8 Characters

    它应该超过8个字符
  3. It should not contain your biometric details such as name, date of birth, place of residence to mention a few.

    它不应包含您的生物特征详细信息,例如姓名,出生日期,居住地点等。

Passwords are stored in an ecrrypted format in the /etc/gshadow file.

密码以加密格式存储在/etc/gshadow文件中。

2.更改其他用户的Linux密码 (2. Changing Linux password for another user)

As discussed before, only the root user can change other users’ password. So, you need to log in as the root user to do this.

如前所述,只有root用户可以更改其他用户的密码。 因此,您需要以root用户身份登录才能执行此操作。

Once logged in run the command as earlier shown to change a users password

登录后,运行前面显示的命令以更改用户密码

# passwd username

Once again, you will be prompted for the new password and asked to confirm it.

再次,将提示您输入新密码并要求您确认。

Sample Output

样本输出

3.强制用户在下次登录时更改密码 (3. Forcing a user to change password at the Next Login)

Usually, passwords are not set to expire. But, you can force a user to change their password the next time they log in to the Linux system.

通常,密码未设置为过期。 但是,您可以强制用户在下次登录Linux系统时更改其密码。

To do this , use the passwd command with --expire option followed by the username of the user:

为此,请使用带有--expire选项的passwd命令以及用户名:

$ passwd --expire jamie

The next time user logs in with their old password, they will be forced to change the password.

下次用户使用旧密码登录时,将被迫更改密码。

Sample Output

样本输出

That concludes this tutorial on How to change a user’s password in Linux. Your contribution and feedback are most welcome.

到此为止,本教程有关如何在Linux中更改用户密码。 非常欢迎您的贡献和反馈。

翻译自: https://www.journaldev.com/28658/change-user-password-linux

linux中更改用户密码

;