当前位置: 移动技术网 > 科技>操作系统>Linux > Linux权限_用户_和用户组

Linux权限_用户_和用户组

2019年07月12日  | 移动技术网科技  | 我要评论

摩托吧交易区,安徽旅游,搞定英文

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/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin
nobody:x:99:99:nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd network management:/:/sbin/nologin
dbus:x:81:81:system message bus:/:/sbin/nologin
polkitd:x:999:998:user for polkitd:/:/sbin/nologin
libstoragemgmt:x:998:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpc:x:32:32:rpcbind daemon:/var/lib/rpcbind:/sbin/nologin
apache:x:48:48:apache:/usr/share/httpd:/sbin/nologin
sshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
quail:x:1000:1000:quail:/home/quail:/bin/bash

/etc/shadow 保存用户密码(以加密形式保存)

[root@localhost ~]# cat /etc/shadow
root:$6$onr1v9vjot8cnlja$xyqjy3pjuydp7cifuheusa1mwjissr4kri.ahiew8dcdvyqa36hjj5tkfynrinoiou.kvmrkfs43hfmxz4uqi1::0:99999:7:::
bin:*:17834:0:99999:7:::
daemon:*:17834:0:99999:7:::
adm:*:17834:0:99999:7:::
lp:*:17834:0:99999:7:::
sync:*:17834:0:99999:7:::
shutdown:*:17834:0:99999:7:::
halt:*:17834:0:99999:7:::
mail:*:17834:0:99999:7:::
operator:*:17834:0:99999:7:::
games:*:17834:0:99999:7:::
ftp:*:17834:0:99999:7:::
nobody:*:17834:0:99999:7:::
systemd-network:!!:18085::::::
dbus:!!:18085::::::
polkitd:!!:18085::::::
libstoragemgmt:!!:18085::::::
abrt:!!:18085::::::
rpc:!!:18085:0:99999:7:::
apache:!!:18085::::::
sshd:!!:18085::::::
postfix:!!:18085::::::
ntp:!!:18085::::::
chrony:!!:18085::::::
tcpdump:!!:18085::::::
quail:$6$kc3nu.izbnlhjb/w$uqpsqjng5iat4a0zn.be9qp/wway3p8ou.ha.o/hr8miqyt0ux7gn1mtyzosfiobl4ere3l4bybeyi.husphb.::0:99999:7:::

  字段解析: (用户名):(加密密码):(密码最后更新时间):(修改间隔):(密码时效性不):(快到期警告时间):(到期宽限时 间):(账号失效时间):(保留)

/etc/group 保存组信息

 

[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
input:x:999:
systemd-journal:x:190:
systemd-network:x:192:
dbus:x:81:
polkitd:x:998:
libstoragemgmt:x:997:
ssh_keys:x:996:
abrt:x:173:
rpc:x:32:
apache:x:48:
sshd:x:74:
slocate:x:21:
postdrop:x:90:
postfix:x:89:
ntp:x:38:
chrony:x:995:
tcpdump:x:72:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
quail:x:1000:quail
字段解析: 用户组名:密码:gid号:组中附加的用户

 

/etc/login.defs 用户属性限制,密码过期时间,密码最大长度等限制

 

[root@localhost ~]# cat /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.
#

# *required*
#   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

# 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_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 is initialized to this value. if not specified, 
# the permission mask will be initialized to 022.
umask           077

# this enables userdel to remove user groups if no members exist.
#
usergroups_enab yes

# use sha512 to encrypt password.
encrypt_method sha512 

 

/etc/default/useradd 显示或更改默认的useradd配置文件

 

[root@localhost ~]# cat /etc/default/useradd 
# useradd defaults file
group=100
home=/home
inactive=-1
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--. 1 root root 107 jul 10 22:16 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--. 2 root root 107 jul 10 22:16 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 为目录的名,或者文件名。

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网