linux passwd用法,Linux passwd初学者命令教程(8个示例)

Linux passwd初学者命令教程(8个示例)

作为Linux命令行用户,您应该了解可帮助您进行用户帐户管理的实用程序。 一旦这样的工具被passwd ,它允许你改变你的账户密码。 在本教程中,我们将使用一些易于理解的示例来讨论此命令的基础知识。

但在这之前,值得一提的是本教程中的所有示例都已在Ubuntu 16.04 LTS机器上进行了测试。

Linux passwd命令

正如开头已经提到的那样,passwd命令让用户更改他们的账户密码。 以下是它的语法:

passwd [options] [LOGIN]

以下是手册页描述的方式:The passwd command changes passwords for user accounts. A normal user

may only change the password for his/her own account, while the

superuser may change the password for any account.  passwd also changes

the account or associated password validity period.

以下是一些问答式样的例子,应该给你一个关于这个命令如何工作的好主意。

Q1。 如何使用passwd?

基本用法很简单 - 只需执行passwd命令即可使用任何选项/输入。

passwd

以下是您需要了解passwd操作的一些有用信息:The user is first prompted for his/her old password, if one is present.

This password is then encrypted and compared against the stored

password. The user has only one chance to enter the correct password.

The superuser is permitted to bypass this step so that forgotten

passwords may be changed.

After the password has been entered, password aging information is

checked to see if the user is permitted to change the password at this

time. If not, passwd refuses to change the password and exits.

The user is then prompted twice for a replacement password. The second

entry is compared against the first and both are required to match in

order for the password to be changed.

Then, the password is tested for complexity. As a general guideline,

passwords should consist of 6 to 8 characters including one or more

characters from each of the following sets:

·   lower case alphabetics

·   digits 0 thru 9

·   punctuation marks

Care must be taken not to include the system default erase or kill

characters.  passwd will reject any password which is not suitably

complex.

例如,就我而言,以下是我更改passwd的方式:

8c8a6a818a273a36811209eb8e8e2d5d.png

请注意,如果您拥有超级用户权限(或系统管理员),则只需提及帐户的用户名即可更改任何帐户的密码。 例如:

passwd himanshu

Q2。 如何创建一个无密码帐户?

passwd命令还允许您删除与用户帐户关联的密码。 为此,您需要使用-d命令行选项。

passwd -d

因此,这基本上是一种快速禁用帐户密码的方式,实质上使其无密码。

Q3。 如何强制过期密码?

有时系统管理员可能希望用户立即更改密码。 因此,在这种情况下,他们可能会使用-e命令行选项,导致密码立即失效,迫使用户在下次登录时更改其密码。

passwd -e

Q4。 如果密码过期,如何禁用帐户?

passwd命令还可以处理以下情况:用户即使在密码过期后也不采取任何操作。 基本上,该工具可让您在完全禁用密码的情况下,以防密码过期达数天。 这可以使用-i命令行选项,它需要一个数字作为输入。

例如:

passwd -i 5

因此,如果密码保持过期5天,此命令将确保帐户被禁用。

Q5。 如何设置密码更改之间的时间差距?

passwd命令还允许您设置密码更改之间的最小时间间隔。 这是通过-n命令行选项实现的,该命令行选项要求数字值被视为天数。

例如:

passwd -n 10

这个命令可以确保任何两次密码更改之间有10天的差距。 值得一提的是,值为0表示用户可以随时更改他/她的密码。

Q6。 如何使passwd显示帐户状态信息?

这可以使用-S命令行选项来完成。

8f610384aab3e016ba9b45efc98a8c9b.png

以下是官方文件解释这些字段的方式:Display account status information. The status information consists

of 7 fields. The first field is the user's login name. The second

field indicates if the user account has a locked password (L), has

no password (NP), or has a usable password (P). The third field

gives the date of the last password change. The next four fields

are the minimum age, maximum age, warning period, and inactivity

period for the password. These ages are expressed in days.

Q7。 如何设置密码有效期?

passwd命令允许您通过-x选项执行此操作,该选项需要表示密码保持有效的最长天数的数字。

例如:

passwd -x 100

Q8。 如何使passwd警告用户应对密码更改?

这可以使用-w命令行选项完成,该选项需要一个数字作为输入,这只是密码过期前的几天,用户将被警告他/她的密码即将过期。

例如:

passwd -w 7

结论

所以你可以看到passwd是一个非常重要的工具,你应该知道,不管你是哪种类型的用户(新手或专业人员)。 在这里,在本教程中,我们已经讨论了passwd的几个关键特性。 练习这些,一旦完成,请前往该工具的手册页以了解更多信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值