Shell command - User group management of passwd, chage

Document and content processing - passwd, chage

1. passwd: change password

Function Description passwd command

passwdCommand to change the user's password

Passwd command syntax

passwd[-k] [-l] [-u [-f]] [-d] [-S] [username]
passwd[parameter] [user]

Description of common parameters passwd command:

passwdMany parameters in Table 1 for the passwdparameters and descriptions of commands:

Table 1: passwd Parameters and descriptions of commands

Parameter options explain
-d Delete password
-f Enforcement
-k After the update can only be sent in expired
-l Stop using an account
-S Show password information
-u Enable has been stopped Account
-x Setting a password is valid
-g Modify the group password
-i After stopping the user account expiration
--help Displays help information

Hands-passwd command

Example 1: change password

[root@m01 ~]# useradd usertest #添加新用户
[root@m01 ~]# passwd usertest #设置密码
Changing password for user usertest.
New password: #输入新密码,密文,无显示
BAD PASSWORD: The password is shorter than 8 characters #提示密码简单
Retype new password: #确认密码
passwd: all authentication tokens updated successfully. #表示成功

Example 2: displaying account password information

[root@m01 ~]# passwd -S usertest 
usertest PS 2019-05-23 0 99999 7 -1 (Password set, SHA512 crypt.)

Example 3: Delete user password

[root@m01 ~]# passwd -d usertest 
Removing password for user usertest.
passwd: Success

2. chage: change the user password expiration date

Chage command function description

chage Command is to modify the password and account expiration date

Chage command syntax

chage[Options] the LOGIN
chage[parameters] [user]

chage common parameters command Description:

chageSmall parameters in Table 1 for the chageparameters and descriptions of commands:

Table 1: chage Parameters and descriptions of commands

Parameter options explain
-m The minimum number of days a password can be changed. Representatives at any time to zero can change the password.
-M A password is valid maximum number of days.
-w Former user password expires, the number of days in advance receive a warning message.
-E Date account expires. After this day, this account will not be available.
-d The last date change.
-i Period of stagnation. If a password has expired these days, then the account will not be available.
-l Setting the current embodiment. By a non-privileged user to determine when their password or account expiration.

Chage command of practical operation

Example 1: You can edit /etc/login.defsto set a few parameters, set default password after you prevail in accordance with the parameters set:

PASS_MAX_DAYS   99999
PASS_MIN_DAYS   0
PASS_MIN_LEN    5
PASS_WARN_AGE   7

Example 2: In /etc/default/useraddcan be found in the following two parameters are set:

# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yesa

Example 3: View user information

[root@m01 ~]# chage -l usertest
Last password change                    : May 23, 2019 #最近一次密码修改时间  
Password expires                    : never #密码过期时间 
Password inactive                   : never #密码失效时间  
Account expires                     : never #帐户过期时间 
Minimum number of days between password change      : 0 #两次改变密码之间相距的最小天数
Maximum number of days between password change      : 99999 #两次改变密码之间相距的最大天数
Number of days of warning before password expires   : 7 #在密码过期之前警告的天数

Example 4: change the user password expiration time

[root@m01 ~]# chage -M 60 usertest 
[root@m01 ~]# chage -l usertest 
Last password change                    : May 23, 2019
Password expires                    : Jul 22, 2019
Password inactive                   : never
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 60
Number of days of warning before password expires   : 7

Example 5: set a password expiration time

[root@m01 ~]# chage -I 5 usertest 
[root@m01 ~]# chage -l usertest
Last password change                    : May 23, 2019
Password expires                    : Jul 22, 2019
Password inactive                   : Jul 27, 2019
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 60
Number of days of warning before password expires   : 7

You can see from the above command, five days after password expiration, password expire automatically, the user will be unable to log in the system.

Today I write to you, have any questions or something goes wrong, feel free to enlighten the great God who comment

Guess you like

Origin blog.51cto.com/14068656/2412981