用戶和用戶組
Linux安全上下文:
運行中的程序:進程
進程所能夠訪問資源的權限取決於進程的運行者身份
用戶必須屬於一個且僅有一個主組(主組可以改為其他組)
私有組:創建用戶時默認指定,就是與用戶同名的組
用戶的附加組:一個用戶可以屬於零個或多個附加組
涉及的配置文件
/etc/passwd:保存用戶信息
whatis passwd
sslpasswd (1ssl) - compute password hashes
passwd (1) - update user's authentication tokens
passwd (5) - password file
man 5 passwd
group(5)).
the full username. Some programs (for example, finger(1)) display information from this field.
was sold to Honeywell. Dennis Ritchie has reported: "Sometimes we sent printer output or batch jobs to the GCOS machine. The
gcos field in the password file was a place to stash the information for the $IDENTcard. Not elegant."
used to set the HOME environment variable.
login through login(1). The value in this field is used to set the SHELL environment variable.
/etc/shadow:保存用戶密碼(加密形式)
It must be a valid account name, which exist on the system.
Refer to crypt(3) for details on how this string is interpreted.
a unix password to log in (but the user may log in the system by other means).
which read the /etc/shadow file may decide not to permit any access at all if the password field is empty.
the password field before the password was locked.
The date of the last password change, expressed as the number of days since Jan 1, 1970.
The minimum password age is the number of days the user will have to wait before she will be allowed to change her password again.
The maximum password age is the number of days after which the user will have to change her password.
will log in.
The number of days before a password is going to expire (see the maximum password age above) during which the user should be warned.
The number of days after a password has expired (see the maximum password age above) during which the password should still be accepted
(and the user should update her password during the next login).
should contact her administrator.
The date of expiration of the account, expressed as the number of days since Jan 1, 1970.
login. In case of a password expiration, the user is not allowed to login using her password.
This field is reserved for future use.
/etc/login.defs:用戶屬性
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
#
# Directory where mailboxes reside, _or_ name of file, relative to the
# home directory. If you _do_ define both, MAIL_DIR takes precedence.
# QMAIL_DIR is for Qmail
#
#QMAIL_DIR Maildir
MAIL_DIR /var/spool/mail
#MAIL_FILE .mail
#
# PASS_MAX_DAYS Maximum number of days a password may be used.
# PASS_MIN_DAYS Minimum number of days allowed between password changes.
# PASS_MIN_LEN Minimum acceptable password length.
# PASS_WARN_AGE Number of days warning given before a password expires.
#
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
# Min/max values for automatic uid selection in useradd
#
UID_MIN 1000
UID_MAX 60000
# System accounts
SYS_UID_MIN 201
SYS_UID_MAX 999
# Min/max values for automatic gid selection in groupadd
#
GID_MIN 1000
GID_MAX 60000
# System accounts
SYS_GID_MIN 201
SYS_GID_MAX 999
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD /usr/sbin/userdel_local
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME yes
# the permission mask will be initialized to 022.
UMASK 077
#
USERGROUPS_ENAB yes
ENCRYPT_METHOD SHA512
/etc/defaults/useradd:默認的useradd配置文件(使用useradd時進行的默認操作)
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
/etc/group
/etc/gshadow
新建用戶之后,系統默認進行的操作
在/etc/passwd中添加用戶信息
如使用passwd命令創建密碼,密碼會被加密保存在/etc/shadow中
為用戶hjm創建家目錄/home/hjm
將/etc/skel/下的所有文件復制到hjm的家目錄
創建與用戶名相同的hjm組,hjm用戶默認屬於hjm同名組
hjm組的信息保存到/etc/group中
useradd命令
useradd [options] LOGIN
-b, --base-dir BASE_DIR
The default base directory for the system if -dHOME_DIR is not specified. BASE_DIR is concatenated with the account name to define the home directory.
The BASE_DIR must exist otherwise the home directory cannot be created.
-d, --home-dir HOME_DIR
The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use
that as the login directory name.
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace.
The groups are subject to the same restrictions as the group given with the -g option. The default is for the user to belong only to the initial group.
-s, --shell SHELL
The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by
the SHELL variable in /etc/default/useradd, or an empty string by default.
Create a system account.
defined in /etc/login.defs, instead of UID_MIN-UID_MAX (and their GID counterparts for the creation of groups).
specify the -m options if you want a home directory for a system account to be created.
-N, --no-user-group
Do not create a group with the same name as the user, but add the user to the group specified by the -g option or by the GROUP variable in
/etc/default/useradd.
