passwd命令詳解

 

基礎命令學習目錄首頁html

 

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

語法

passwd(選項)(參數)

選項

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

參數

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

知識擴展

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

存放用戶信息:學習

  1.  
    /etc/passwd
  2.  
    /etc/shadow

存放組信息:加密

  1.  
    /etc/group
  2.  
    /etc/gshadow

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

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

組信息文件分析.net

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

實例

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

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

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

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

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

  1.  
    [root@localhost ~]# passwd -l linuxde //鎖定用戶linuxde不能更改密碼;
  2.  
    Locking password for user linuxde.
  3.  
    passwd: Success //鎖定成功;
  4.  
     
  5.  
    [linuxde@localhost ~]# su linuxde //經過su切換到linuxde用戶;
  6.  
    [linuxde@localhost ~]$ passwd //linuxde來更改密碼;
  7.  
    Changing password for user linuxde.
  8.  
    Changing password for linuxde
  9.  
    (current) UNIX password: //輸入linuxde的當前密碼;
  10.  
    passwd: Authentication token manipulation error //失敗,不能更改密碼;

再來一例:

  1.  
    [root@localhost ~]# passwd -d linuxde //清除linuxde用戶密碼;
  2.  
    Removing password for user linuxde.
  3.  
    passwd: Success //清除成功;
  4.  
     
  5.  
    [root@localhost ~]# passwd -S linuxde //查詢linuxde用戶密碼狀態;
  6.  
    Empty password. //空密碼,也就是沒有密碼;

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

 轉自:http://man.linuxde.net/passwd

相關文章
相關標籤/搜索