歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux基礎知識 >> linux用戶和組管理

linux用戶和組管理

日期:2017/3/2 17:13:19   编辑:Linux基礎知識

用戶和組相關文件,useradd

1.用戶和組相關文件

(1) /etc/passwd

  格式:name:passwd:UID:GID:GECOS:directory:shell

     zhubiao:x:1000:1000:zhubiao:/home/zhubiao:/bin/bash

  1 name : user's login name

  2 passwd : x占位,實際存放於/etc/shadow

  3 UID : user ID, 用戶代碼

    User ID 的范圍由/etc/login.defs UID_MIN UID_MAX決定 [UID_MIN,UID_MAX]

    系統賬號:1-499 , 1-999

    普通賬號:500+, 1000+

  4 GID : group ID , 組代碼

    group ID 的范圍由/etc/login.defs GID_MIN GID_MAX決定 [GID_MIN,GID_MAX]

    系統組 : 1-499 , 1-999

    普通組 : 500+, 1000+

    組類別:

      基本組:

        私有組:組名和用戶名相同,且僅包含一個用戶

      附加組:

  5 GECOS : comment filed, 摘要字段

  6 direcotory : user's home directory, 用戶家目錄

    家目錄默認目錄由/dev/default/passwd 中"HOME=/home"決定

    加目錄配置文件由/dev/default/passwd 中"SKEL=/etc/skel"決定

  7 shell : set the SHELL environment variable , if empty, use /bin/sh

    默認值/dev/default/passwd 中 "SHELL=/bin/bash" 

(2) /etc/shadow

  格式:name:password:last_chage_date:minimum_age:Maximum_age:warning_period:inactivity_period

      :expiration_date:reserved_filed

  1 name : login name

  2 password : encrypted password, 加密後的密碼

    加密算法:md5sum(message digest), sha1sum(secure hash algorithm), sha224sum, sha256sum, sha384sum, sha512sum

      這些加密算法的特征:

        蝴蝶效應:初始條件發生微小改變,將會引起結果的巨大改變

        定長輸出

    密碼中還加入了雜質以避免不同用戶相同密碼加密後密碼相同

  3 last_chage_date : date of last password change, 最近一次修改密碼的日期

  4 minimum_age : minium password age, 修改密碼最短間隔期

  5 maxinmu_age : maxinum password age, 密碼最長使用期限

  6 warning_period : password warning period, the number of days before a password is going to expier

            during which the user should be warned, 在密碼時效前幾天警告用戶

  7 inactivity_period : password inactivity period, the number of days after a password has expired during

             which the password should still be accepted, 密碼失效後仍未修改保留密碼可用的天數

  8 expiration_date : account expiration date, 用戶有效期限

(3) /etc/group

  格式:group_name:password:GID:user_list

    groupA:x:504:zhubiao,xiaocao,user1,user12

  1 group_name : the name of the group

  2 password : 使用x占位,密碼保存於/etc/gshadow

  3 GID : group ID

  4 user_list : a list of usernames that are members of this group, 該組中所包含的用戶,多個用戶之間用","隔開

(4) /etc/gshadow

  格式:group_name:password:administrators:members

    groupD:!::user12

2. useradd : create a new user or update default new user information

  -u : --uid UID 取值范圍[MIN_UID, MAX_UID] , this value must be unique

  -g : --gid GROUP the group name or group id, the group name and group id must exit. 組名或組編號,組必須存在

  -c : --comment COMMENT, any text string

  -d : --home HOME_DIR,家目錄路徑,最好該路徑以前不存在,默認路徑由/etc/default/useradd文件規定,

    目錄配置文件從/etc/skel/中復制

  -s : --shellSHELL,默認路徑由/etc/default/useradd文件規定

  -G : --groups GROUP1,GROUP2,GROUP3..., 附加組

  -M : 不建家目錄(系統用戶默認)

  -m : 建用戶家目錄(普通用戶默認)

  -D : --defaults

    -g : --gid GROUP, /etc/default/useradd "GROUP=100"

    -b : --base-dir HOME, /etc/default/useradd "HOME=/home"

    -f : --inactive INACTIVE,the numser of days after a password has expiered before the account will be disabled,

      修改密碼失效後仍未修改,密碼仍可用的期限, /etc/default/passwd "INACTIVE=1"

    -e : --expiredate EXPIRE, 賬號可用期限,/etc/default/useradd "EXPIRE=30"

Copyright © Linux教程網 All Rights Reserved