Linux培训笔记之用户、组及权限

Linux培训笔记之用户、组及权限

--------------------------------------分割线 --------------------------------------

--------------------------------------分割线 --------------------------------------

一、user
1.每个用户将指派唯一用户ID(UID)
  root的ID为0
  普通用户ID从500开始(0-500系统使用)
2.用户名和用户ID存在 /etc/passwd中
3.当用户登陆时系统自动为其分配一个用户家目录
4.用户无法读、写、执行其他用的文件
二、changing file ownership
1.only root can change a file's owner
2.only root or the owner can change a file's group
3.ownership is changed with chown:
  chown [-R]用户名 file|directory (-R参数可以递归将文件夹及其子文件全部修改)
4.group-ownnership is change with chgrp:
  chgrp [-R]组名 file|directory
例:
[root@instructor ~]# cd /tmp
[root@instructor tmp]# mkdir ownership
[root@instructor tmp]# cd ownership
[root@instructor ownership]# ls -l
total 0
[root@instructor ownership]# cp /etc/passwd ./
[root@instructor ownership]# ls -l
total 4
-rw-r--r--. 1 root root 2051 Jan  2 14:42 passwd
[root@instructor ownership]# pwd
/tmp/ownership
[root@instructor ownership]#
[root@instructor ownership]# chown eric passwd
[root@instructor ownership]# ll
total 4
-rw-r--r--. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]#
三、changing permissions  字母方式
1.to change access modes:(修改访问模式)
  chmod [-option]...mode[,mode] file|directory
2.mode includes:
  -u,g or o for user,group and other
eg:
[root@instructor ~]# cd /tmp
[root@instructor tmp]# cd ownership
[root@instructor ownership]# ls -l
total 4
-rw-r--r--. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]#
[root@instructor ownership]# chmod ugo+x passwd
[root@instructor ownership]# ls -l
total 4
-rwxr-xr-x. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]#
or:
[root@instructor ownership]# chmod a+x passwd
[root@instructor ownership]# chmod a-x passwd
[root@instructor ownership]# ls -l
total 4
-rw-r--r--. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]#
 -+,- or = for grant,deny or set
  -r,w or x for read,write and execute
3.option include(递归修改)
  - -R recursive
4.examples:
  - chmod ugo+r file:grant access to all for file
    (所有用户添加可读权限)
  - chmod o-wx dir:deny write and execute to others for dir
    (other用户去掉可写和可执行权限)
四、changing permissions 数字方式
1.uses a thress-digit mode number
  -first digit specifies owner's permissions
  (第一位数字代表用户的权限)
  -second digit specifies group permissions
  (第二位数字代表group的权限)
  -third digit represents others' permissions
  (第三位数字代表others的权限)
eg:
  ---      000
  --x      001
  -w-      010
  -wx      011
  r--      100
  r-x      101
  rw-      110
  rwx      111
将某文件的权限修改为:rwxr-x---(用户读写可执行,组可读可执行,other无权限)
rwxr-x---:750
[root@instructor ownership]# ls -l
total 4
-rw-r--r--. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]# chmod 750 passwd
[root@instructor ownership]# ls -l
total 4
-rwxr-x---. 1 eric root 2051 Jan  2 14:42 passwd
[root@instructor ownership]#
2.permissions are calculated by adding:
  -4(for read)
  -2(for write)
  -1(for execute)
3.example:
  -chmod 640 myfile
五、user and group ID number
1.user names map to user ID number
2.group names map to group ID number
3.data stored on the hard disk is stored numberically
六、/etc/passwd,/etc/shadow,and /etc/group files
authentication information is stored in plain text files:
  - /etc/passwd  (用户信息)
  - /etc/shadow  (密码信息)
  - /etc/group  (用户组信息)
  - /etc/gshadow (不再使用)
1./etc/passwd
  user account information
eg:
[root@instructor tmp]# tail -2 /etc/passwd
tommy:x:502:503::/home/tommy:/bin/bash
test:x:503:504::/home/test:/bin/bash
col1:user name (tommy)
col2:placeholder (占位符,现在不用)
col3:user ID (502)
col4:user group ID (503)
col5:comment (自定义信息)
col6:user home directory (/home)
col7:user login shell (/bin/bash)
2./etc/shadow
  user password information
eg:
[root@instructor ~]# tail -2 /etc/shadow
tommy:!!:15952:0:99999:7:::
test:$6$v0bJ8hdm$YfydydPHkYA4s7VrsR8ZHGb2eofMsEe9VPXDwSxWKWJ/HZxcbPnu7quKsPru/IWOyYwPzWsgp7OXZ.PIduyoq.:15955:0:99999:7:::
col1:user name
col2:encrypted user password
col3:last password change(since 1970-1-1)
col4:the minimum number of days between password changes(0)
col5:the maximum number of days the password is valid(99999)
col6:the number of days before password is to expired that user is warned(7)
col7:the number of day after password expires that account is disabled
col8:days since Jan 1,1970 that account is disable
col9:reserved(保留)
3./etc/group
  user account information
eg:
[root@instructor ~]# grep "adm" /etc/group
sys:x:3:bin,adm
adm:x:4:adm,daemon
desktop_admin_r:x:498:

相关推荐