Linux用户用户组及权限管理
用户和用户组
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.