天天看點

usermod指令、使用者密碼管理、mkpasswd指令

usermod指令

usermod [options] user_name

usermod :可用來修改使用者帳号的各項設定

[options]

-a|--append  ##把使用者追加到某些組中,僅與-G選項一起使用 

-c|--comment ##修改/etc/passwd檔案第五段comment 

-d|--home    ##修改使用者的家目錄通常和-m選項一起使用 

-e|--expiredate  ##指定使用者帳号禁用的日期,格式YY-MM-DD 

-f|--inactive    ##使用者密碼過期多少天後采用就禁用該帳号,0表示密碼已過期就禁用帳号,-1表示禁                                用 此功能,預設值是-1 

-g|--gid     ##修改使用者的gid,改組一定存在

-G|--groups  ##把使用者追加到某些組中,僅與-a選項一起使用 

-l|--login   ##修改使用者的登入名稱 

-L|--lock    ##鎖定使用者的密碼 

-m|--move-home   ##修改使用者的家目錄通常和-d選項一起使用 

-s|--shell   ##修改使用者的shell 

-u|--uid     ##修改使用者的uid,該uid必須唯一 

-U|--unlock  ##解鎖使用者的密碼

1、新增使用者

[root@test ~]# useradd gz

You have new mail in /var/spool/mail/root

[root@test ~]# id gz

uid=510(gz) gid=510(gz) groups=510(gz)

[root@test ~]# groupadd gd

2、添加到gd組

[root@test ~]# usermod -aG gd  gz

uid=510(gz) gid=510(gz) groups=510(gz),511(gd)

3、修改使用者的名稱

[root@test ~]# usermod -l gztest gz

id: gz: No such user

[root@test ~]# id gztest

uid=510(gztest) gid=510(gz) groups=510(gz),511(gd)

4、鎖定賬号

[root@test ~]# usermod -L gztest

5、解鎖賬号

[root@test ~]# usermod -U gztest

6、修改使用者UID、GID

[root@test ~]# usermod -u 555 gztest

[root@test ~]# usermod -g 111 gztest

uid=555(gztest) gid=111(op) groups=111(op),511(gd)

7、指定賬号過期時間

[root@test ~]# usermod -e 2017-10-26 gztest

8、指定使用者多少天後過期,過期後禁用使用者

[root@test ~]# usermod -f 0 gztest

使用者密碼管理

-m:密碼可更改的最小天數。為零時代表任何時候都可以更改密碼。 

-M:密碼保持有效的最大天數。 

-w:使用者密碼到期前,提前收到警告資訊的天數。 

-E:帳号到期的日期。過了這天,此帳号将不可用。 

-d:上一次更改的日期。 

-i:停滞時期。如果一個密碼已過期這些天,那麼此帳号将不可用。 -l:例出目前的設定。由非特權使用者來确定他們的密碼或帳号何時過期。

[root@test ~]# chage -l test

Last password change : password must be changed

Password expires : password must be changed

Password inactive : password must be changed

Account expires : never

Minimum number of days between password change (在多少天内密碼更改的最小天數) : 0

Maximum number of days between password change (最大天數) : 1

Number of days of warning before password expires(密碼過期前警告天數) : 2

[root@test ~]# chage -M 60 -m 7 -W 7 test

設定test使用者60天後密碼過期,至少7天後才能修改密碼,密碼過期前7天開始收到告警資訊。

passwd修改密碼:

[root@test ~]# echo "gztest" |passwd --stdin gztest

Changing password for user gztest.

passwd: all authentication tokens updated successfully.

mkpasswd指令

Linux系統有一個自帶的生成密碼的指令

[root@test ~]# mkpasswd -l 8

yE82Tka/

[root@test ~]# mkpasswd -l 9

bq"l1TA8m

-l #指定密碼的長度,預設是7位數

-d #指定密碼中數字最少位數,預設是2位

-c #指定密碼中小寫字母最少位數,預設是2位

-C #指定密碼中大寫字母最少位數,預設是2位

-s #指定密碼中特殊字元最少位數,預設是1位

[root@test ~]# mkpasswd -l 9 -d 3 -c 2 -C 2 -s 1

297zsRZd(

本文轉自 jiekegz  51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/1976042

繼續閱讀