如何在Linux中使用passwd命令更改用户密码?

passwd command is used to change passwords and provides information about Linux accounts. Normal or root user can change passwords. Normal users can only change their own password on the other hand root can change all user’s passwords. Passwords related information is stored in /etc/passwd file. The only password which is stored as the hash is stored in /etc/shadow .

passwd命令用于更改密码,并提供有关Linux帐户的信息。 普通或root用户可以更改密码。 普通用户只能更改自己的密码,而另一方面,root用户可以更改所有用户的密码。 与密码有关的信息存储在/etc/passwd文件中。 唯一作为哈希存储的密码存储在/etc/shadow

用户密码文件 (User Password File)

As stated previously user account related information is stored in /etc/passwd . There is information like

如前所述,用户帐户相关信息存储在/etc/passwd 。 有类似的信息

  • username

    用户名
  • password which is X refers to the /etc/shadow file

    X的密码是指/etc/shadow文件

  • User ID

    用户身份
  • Group ID

    组号
  • User ID information

    用户ID信息
  • Home directory

    主目录
  • Command or shell

    命令或外壳

Here is an example passwd  file.

这是一个示例passwd文件。

$ cat /etc/passwd
Password File
Password File
密码档案

更改当前用户密码(Change Current User Password)

We will start by simply changing the current user password. We do not need to provide any user name because the currently logged in user will be used.

我们将从简单地更改当前用户密码开始。 我们不需要提供任何用户名,因为将使用当前登录的用户。

$ passwd
Change Current User Password
Change Current User Password
更改当前用户密码

Before entering a new password we should provide a current password. The new password should be different than the existing one.

在输入新密码之前,我们应该提供一个当前密码。 新密码应与现有密码不同。

更改指定的用户密码 (Change Specified User Password)

We can change different users than current users. We will specify the user name we want to change the password. We should have root privileges. We will run commands with sudo for root privilege. In this example, we will change the user ismail password.

我们可以更改与当前用户不同的用户。 我们将指定要更改密码的用户名。 我们应该具有root特权。 我们将使用sudo运行命令以获得root特权。 在此示例中,我们将更改用户ismail密码。

$ sudo passwd ismail

显示指定的用户密码状态 (Show Specified User Password Status)

Password status is used to show current account password expire or validity dates. We will use -S  option with the user name like below.

密码状态用于显示当前帐户密码过期或有效日期。 我们将使用-S选项,其用户名如下所示。

$ passwd -S ismail
Show Specified User Password Status
Show Specified User Password Status
显示指定的用户密码状态

显示所有用户密码状态(Show All Users Password Status)

In the previous example, we have only shown the given user account or password status. We have the chance to list all users. But we need root privileges again. We will use -l with -S like below.

在前面的示例中,我们仅显示了给定的用户帐户或密码状态。 我们有机会列出所有用户。 但是,我们再次需要root特权。 我们将-l-S一起使用,如下所示。

$ sudo passwd -a -S
Show All Users Password Status
Show All Users Password Status
显示所有用户密码状态

锁定指定的用户帐户和密码(Lock Specified User Account and Password)

If we need to stop users from logging by locking the account. We will provide the account name with the -l  option. In this example, we will lock the account named john.

如果我们需要通过锁定帐户来阻止用户登录。 我们将为帐户名提供-l选项。 在此示例中,我们将锁定名为john的帐户。

$ sudo passwd -l john

解锁指定的用户帐户和密码 (Unlock Specified User Account and Password)

Locking user accounts is a security measure useful if the user will not use it for a period of time the system. For example, a user will do a holiday for two months and the account should be locked for this period of time. We can also unlock the account with the -u option like below.

如果用户在一段时间内不使用它,锁定用户帐户是一种安全措施。 例如,用户将假期两个月,并且该帐户应在这段时间内被锁定。 我们还可以使用-u选项解锁该帐户,如下所示。

$ sudo passwd -u john

删除或清空用户密码 (Delete or Make Empty User Password)

We can make the user password empty. This will disable the password for the given user account. We will use -d option with the username. In this example, we will disable password for user john .

我们可以将用户密码设为空。 这将禁用给定用户帐户的密码。 我们将使用-d选项和用户名。 在此示例中,我们将禁用用户john密码。

$ sudo passwd -d john
LEARN MORE  What Is User In Computing, Windows, Linux, Google?
了解更多什么是计算,Windows,Linux,Google中的用户?

翻译自: https://www.poftut.com/change-user-password-passwd-linux-etc-passwd-file/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值