passwd命令

passwd命令用於設置用戶的認證信息,包括用戶密碼、密碼過時時間等。系統管理者則能用它管理系統用戶的密碼。只有管理者能夠指定用戶名稱,通常用戶只能變動本身的密碼。linux

語法

passwd(選項)(參數)

選項

-d:刪除密碼,僅有系統管理者才能使用;
-f:強制執行;
-k:設置只有在密碼過時失效後,方能更新;
-l:鎖住密碼;
-s:列出密碼的相關信息,僅有系統管理者才能使用;
-u:解開已上鎖的賬號。

參數

用戶名:須要設置密碼的用戶名。bash

知識擴展

與用戶、組帳戶信息相關的文件加密

存放用戶信息:spa

/etc/passwd
/etc/shadow

存放組信息:.net

/etc/group
/etc/gshadow

用戶信息文件分析(每項用:隔開)code

例如:jack:X:503:504:::/home/jack/:/bin/bash
jack  //用戶名
X  //口令、密碼
503  //用戶id(0表明root、普通新建用戶從500開始)
504  //所在組
:  //描述
/home/jack/  //用戶主目錄
/bin/bash  //用戶缺省Shell

組信息文件分析token

例如:jack:$!$:???:13801:0:99999:7:*:*:
jack  //組名
$!$  //被加密的口令
13801  //建立日期與今天相隔的天數
0  //口令最短位數
99999  //用戶口令
7  //到7天時提醒
*  //禁用天數
*  //過時天數

實例

若是是普通用戶執行passwd只能修改本身的密碼。若是新建用戶後,要爲新用戶建立密碼,則用passwd用戶名,注意要以root用戶的權限來建立。ip

[root@localhost ~]# passwd linuxde    //更改或建立linuxde用戶的密碼;
Changing password for user linuxde.
New UNIX password:          //請輸入新密碼;
Retype new UNIX password:   //再輸入一次;
passwd: all authentication tokens updated successfully. //成功;

普通用戶若是想更改本身的密碼,直接運行passwd便可,好比當前操做的用戶是linuxde。get

[linuxde@localhost ~]$ passwd
Changing password for user linuxde. //更改linuxde用戶的密碼;
(current) UNIX password:   //請輸入當前密碼;
New UNIX password:         //請輸入新密碼;
Retype new UNIX password:  //確認新密碼;
passwd: all authentication tokens updated successfully. //更改爲功;

好比咱們讓某個用戶不能修改密碼,能夠用-l選項來鎖定:it

[root@localhost ~]# passwd -l linuxde    //鎖定用戶linuxde不能更改密碼;
Locking password for user linuxde.
passwd: Success           //鎖定成功;

[linuxde@localhost ~]# su linuxde   //經過su切換到linuxde用戶;
[linuxde@localhost ~]$ passwd      //linuxde來更改密碼;
Changing password for user linuxde.
Changing password for linuxde
(current) UNIX password:          //輸入linuxde的當前密碼;
passwd: Authentication token manipulation error     //失敗,不能更改密碼;

再來一例:

[root@localhost ~]# passwd -d linuxde  //清除linuxde用戶密碼;
Removing password for user linuxde.
passwd: Success                         //清除成功;

[root@localhost ~]# passwd -S linuxde    //查詢linuxde用戶密碼狀態;
Empty password.                         //空密碼,也就是沒有密碼;

注意:當咱們清除一個用戶的密碼時,登陸時就無需密碼,這一點要加以注意。

相關文章
相關標籤/搜索