Linux中用户UID就判断操作系统中用户的身份。
Centos7.x:
0:超级管理员
1-999:系统用户(包含Linux中自带服务)
1000以上 普通用户
Centos6.x :
Root用户 (ID 0)超级管理员
系统用户 (ID 1-499)
普通用户 (ID 500以上)
Linux中用户的相关的文件
/etc/passwd 保存用户信息
[root@localhost ~]# cat /etc/passwdroot:x:::root:/root:/bin/bash
bin:x:::bin:/bin:/sbin/nologin
daemon:x:::daemon:/sbin:/sbin/nologin
adm:x:::adm:/var/adm:/sbin/nologinlp:x:::lp:/var/spool/lpd:/sbin/nologinsync:x:::sync:/sbin:/bin/syncshutdown:x:::shutdown:/sbin:/sbin/shutdown
halt:x:::halt:/sbin:/sbin/halt
mail:x:::mail:/var/spool/mail:/sbin/nologin
operator:x:::operator:/root:/sbin/nologin
games:x:::games:/usr/games:/sbin/nologinftp:x:::FTP User:/var/ftp:/sbin/nologin
nobody:x:::Nobody:/:/sbin/nologin
systemd-network:x:::systemd Network Management:/:/sbin/nologin
dbus:x:::System message bus:/:/sbin/nologin
polkitd:x:::User for polkitd:/:/sbin/nologin
libstoragemgmt:x:::daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
abrt:x::::/etc/abrt:/sbin/nologin
rpc:x:::Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
apache:x:::Apache:/usr/share/httpd:/sbin/nologin
sshd:x:::Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x::::/var/spool/postfix:/sbin/nologin
ntp:x::::/etc/ntp:/sbin/nologin
chrony:x::::/var/lib/chrony:/sbin/nologin
tcpdump:x::::/:/sbin/nologin
quail:x:::quail:/home/quail:/bin/bash
/etc/shadow 保存用户密码(以加密形式保存)
[root@localhost ~]# cat /etc/shadow
root:$$ONr1v9vJOt8CnljA$xyqJy3PJUyDP7CIfUheuSa1MWjISSr4KRi.AHIEw8DCdVYQa36HjJ5TkFYnRinoiOu.kvmRKFs43HfMXz4UQi1:::::::
bin:*:::::::
daemon:*:::::::
adm:*:::::::lp:*:::::::sync:*:::::::
shutdown:*:::::::
halt:*:::::::
mail:*:::::::
operator:*:::::::
games:*:::::::ftp:*:::::::
nobody:*:::::::
systemd-network:!!:::::::
dbus:!!:::::::
polkitd:!!:::::::
libstoragemgmt:!!:::::::
abrt:!!:::::::
rpc:!!:::::::
apache:!!:::::::
sshd:!!:::::::
postfix:!!:::::::
ntp:!!:::::::
chrony:!!:::::::
tcpdump:!!:::::::
quail:$$Kc3NU.IzbnLHJB/w$UQPSQJng5IAt4a0zn.be9QP/WWay3p8ou.hA.o/hr8mIqYT0UX7Gn1MTyzOsfioBL4ere3l4bYbEyI.HUspHb.:::::::
字段解析: (用户名):(加密密码):(密码最后更新时间):(修改间隔):(密码时效性不):(快到期警告时间):(到期宽限时 间):(账号失效时间):(保留)
/etc/group 保存组信息
[root@localhost ~]# cat /etc/group
root:x::
bin:x::
daemon:x::
sys:x::
adm:x::
tty:x::
disk:x::lp:x::
mem:x::
kmem:x::
wheel:x::
cdrom:x::
mail:x::postfixman:x::
dialout:x::
floppy:x::
games:x::
tape:x::
video:x::ftp:x::
lock:x::
audio:x::
nobody:x::
users:x::
utmp:x::
utempter:x::
input:x::
systemd-journal:x::
systemd-network:x::
dbus:x::
polkitd:x::
libstoragemgmt:x::
ssh_keys:x::
abrt:x::
rpc:x::
apache:x::
sshd:x::
slocate:x::
postdrop:x::
postfix:x::
ntp:x::
chrony:x::
tcpdump:x::
stapusr:x::
stapsys:x::
stapdev:x::
quail:x::quail
字段解析: 用户组名:密码:GID号:组中附加的用户
/etc/login.defs 用户属性限制,密码过期时间,密码最大长度等限制
[root@localhost ~]# cat /etc/login.defs
#
# Please note that the parametersin this configuration filecontrol 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
#passwdcommand) should therefore be configured elsewhere. Refer to
#/etc/pam.d/system-auth for moreinformation.
#
#*REQUIRED*# Directory where mailboxes reside, _or_ name offile, relative to the
# home directory. If you _do_ define both, MAIL_DIR takes precedence.
# QMAIL_DIR isforQmail
#
#QMAIL_DIR Maildir
MAIL_DIR/var/spool/mail
#MAIL_FILE .mail
# Password aging controls:
#
# 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_DAYSPASS_MIN_DAYSPASS_MIN_LENPASS_WARN_AGE#
# Min/max values for automatic uid selection inuseradd
#
UID_MINUID_MAX# System accounts
SYS_UID_MINSYS_UID_MAX#
# Min/max values for automatic gid selection ingroupadd
#
GID_MINGID_MAX# System accounts
SYS_GID_MINSYS_GID_MAX#
# 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 directoriesforusers by default
# On RH systems, wedo. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME yes
# The permission mask is initialized to this value. If not specified,
# the permission mask will be initialized to.
UMASK# This enables userdel to remove usergroups ifno members exist.
#
USERGROUPS_ENAB yes
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
/etc/default/useradd 显示或更改默认的useradd配置文件
[root@localhost ~]# cat /etc/default/useradd
# useradd defaultsfileGROUP=HOME=/home
INACTIVE=-EXPIRE=SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
Linux中用户的权限和归属
Linux权限是操作系统用来限制对资源访问的机制,权限一般分为读、写、执行。系统中每个文件都拥有特定的权 限、所属用户及所属组,通过这样的机制来限制哪些用户或用户组可以对特定文件进行相应的操作。
Linux中有的文件及文件夹都有至少权限三种权限 权限 对文件的影响 对目录的影响 :
r(读取) 可读取文件内容 可列出目录内容
w(写入) 可修改文件内容 可在目录中创建删除内容
x(执行) 可作为命令执行 可访问目录内容
目录必须拥有x权限,否则无法查看其内容
文件权限中首字母判断文件类型
-:普通文件
d :目录文件
l:链接文件
b:块设备文件
c:字符设备文件
p:管道文件
Linux权限授权,默认是授权给三种角色,分别是user、group、other,Linux权限与用户之间的关联如下:
U代表User,G代表Group,O代表Other;
每个文件的权限基于UGO进行设置;
权限的三位一组(rwx),同时需要授权给三种角色,UGO;
每个文件拥有一个所属用户和所属组,对应UGO,不属于该文件所属用户或所属组使用O来表示;
[root@localhost home]# ll test.txt-rwxrw-r--. root root Jul :test.txt
#上面目录权限分解:
#U:rwx----->user------>root 用户对于test.txt拥有的权限(属主)
#G:rw------>group------>root 组对于text.txt拥有的权限 (属组)
#O:r--------other-------> * 其他用户对于test.txt拥有的权限 (其他人)
对于test.txt文件属性参数详解如下:
[root@localhost home]# ll test
drwxrw-r--. root root Jul :test
· d 表示目录,同一位置如果为-则表示普通文件;
· rwxrw-r--表示三种角色的权限,每三位为一种角色,依次为U,G,O权限,如上则表示user的权限为rwx, group的权限为rw-,other的权限为r--;
· 2表示文件夹的链接数量,可理解为该目录下子目录的数量(目录的链接数量至少为2.因为内含:.和..两个特殊目录)
· 从左到右,第一个root表示该用户名(文件所属主,对应前面三位一体权限的“user”),第二个root则为组名 (文件所属组,对应前面三位一体权限的“group”),其他人角色默认不显示(其他人权限,对应前面三位一体权限 的“other”);
· 107表示该文件夹占据的字节数;
· Jul 10 22:16 表示文件创建或者修改的时间;
· test 为目录的名,或者文件名。