Chapter V user identity and file permissions Day 5 July 20

  • User identity and file permissions
  • Manipulate the user's command
    • useradd
      • Format is "useradd [option] username."
    • groupadd
      • groupadd command is used to create groups of users in the format of "groupadd [options] group name"
      • usermod command modifies the user's attributes, the format of "usermod [options] user name."
    • usermod ( modify a user account)
      • usermod [options] user name. "
      •    

    • userdel
      • userdel command to delete a user in the format of "userdel [options] user name."
    • passwd
      • passwd [options] [username]

           

  • Linux file types
  • Three user classification
    • File owner
    • Owned by group
    • Other users
  • Files are belong to the owners and groups.
    • Read, write, execute.
    • Readable representation can read the contents inside
    • Writable represent can add, modify, delete the actual contents of the file.
    • Capable of executing an executable script file.
  • Directory also has the appropriate permissions, but not the same representation.
    • The main content is to record a list of filenames and subdirectories list instead of the actual local storage of data.
    • Read: that can read the directory, to know which files exist there, such as file names and subdirectory names
    • Write:
      • Create a new file or subdirectory.
      • And delete existing files or subdirectories. (So ​​is the ability to delete files to see whether folders have permissions.
      • Rename the existing file or subdirectory.
      • Transfer location of the file or subdirectory.
    • Executable: The user owns the directory x permission can enter the directory becomes the working directory. Can not enter a directory, only with the permission of the x directory, if the user does not have a directory for x permissions, you can not switch to the directory, it can not execute any command in the directory, even with the directory r permission. And if the user does not have a directory for x permissions, the user can not query the contents of files in the directory Note: refers to the content, if there is r permission can view the list of filenames or subdirectories under that directory list . So when you want to browse the Open Directory to anyone, you should at least give the r and x permissions
    • 问题: 对目录只有可读权限,对文件有可写权限,能否修改文件内容?
  • -rwxrw-r-- 1 root root  2048 Jan 13 07:11 afile.exe 以上权限位置的含义
    • file permissions,

      number of links,

      owner name,

      owner group,

      file size,

      time of last modification, and

      file/directory name

      File permissions is displayed as following;

    • first character is - or l or d, d indicates a directory, a line represents a file, l is a symlink (or soft link) - special type of file

      three sets of characters, three times, indicating permissions for owner, group and other:

      r = readable

      w = writable

      x = executable

      In your example -rwxrw-r--, this means the line displayed is:

    • a regular file (displayed as -)

      readable, writable and executable by owner (rwx)

      readable, writable, but not executable by group (rw-)

      readable but not writable or executable by other (r--)

  • SUID,SGID,SBIT特殊权限位。
    • SUID(Set Owner User ID) 是一种对二进制程序进行设置的特殊权限,可以让二进制程序的执行者临时拥有属主的权限(仅对拥有执行权限的二进制程序有效)。比如一个普通用户要执行passwd来修改密码,但是实际上,普通用户属于Other并没有权限,关键在于在执行过程中可以获得
      • SUID满足以下几点
      • SUID只对二进制文件有效
      • 调用者对该文件有执行权
      • 在执行过程中,调用者会暂时获得该文件的所有者权限
      • 该权限只在程序执行的过程中有效
      • 他的标志是,在文件所有者的权限位上,x表示为s
    • SGID
      • 让执行者临时拥有属组的权限(对拥有执行权限的二进制程序进行设置);
      • 在某个目录中创建的文件自动继承该目录的用户组(只可以对目录进行设置)。
    • 使用什么命令来修改权限
      • chmod 修改权限
        • chmod [参数] 权限文件或目录名称 chmod 760 test
      • chown 修改所有者和所属组
        • chmod [参数] 权限文件或目录名称
    • SBIT
      • SBIT(Sticky Bit)特殊权限位了(也可以称之为特殊权限位之粘滞位)。
      • BIT 特殊权限位可确保用户只能删除自己的文件,而不能删除其他用户的文件。换句话说,当对某个目录设置了SBIT 粘滞位权限后,那么该目录中的文件就只能被其所有者执行删除操作了。
      • 这个权限保护位是对目录使用的。
      • 标志在其他用户,文件的其他人权限部分的x 执行权限就会被替换成t 或者T,原本有x 执行权限则会写成t,原本没有x 执行权限则会被写成T。
      • chmod o+t 目录位置
  • 文件的隐藏属性
    • 无法被用户察觉。
    • chattr修改隐藏属性。
      • 如果想要把某个隐藏功能添加到文件上,则需要在命令后面追加"+参数"。
      • 如果想要把某个隐藏功能移出文件,则需要追加"-参数"。
    • chattr [参数] 文件
    •    

    • lsattr用于显示文件的隐藏权限。
    • lsattr [参数] 文件
  • 一般权限、特殊权限、隐藏权限其实有一个共性—权限是针对某一类用户设置的。
  • 文件访问控制列表
    • ACL:用以对单个指定的用户进行单独的权限控制。基于普通文件或目录设置ACL 其实就是针对指定的用户或用户组设置文件或目录的操作权限。
    • 在所属用户和用户组不变的情况下,等于是为其他用户增加权限,相对细。
    • 命令 setfacl ( set file acl )
      • "setfacl [参数] 文件名称" 例子 setfacl -Rm u:linuxprobe:rwx /root
    • 命令 getfacl 获得文件的access control list
  • su 命令与sudo 服务:
    • su (run a command with substitute 替代 user and group ID)
    • 上面的su 命令与用户名之间有一个减号(-),这意味着完全切换到新的用户,即把环境变量信息也变更为新用户的相应信息,而不是保留原始的信息。强烈建议在切换用户身份时添加这个减号(-)
    • sudo (execute a command as another user)给普通用户提供额外的权限来完成原本root 管理员才能完成的任务,格式为"sudo [参数] 命令名称"
      • sudo是一个服务
      • sudo的配置原则:用户的最小权限原则。
        • 限制用户执行指定的命令:
        • 记录用户执行的每一条命令;
        • 配置文件(/etc/sudoers)提供集中的用户管理、权限与主机等参数;
        • 验证密码的后5 分钟内(默认值)无须再让用户再次验证密码。
      • 如何配置sudo?
        • visudo 类似Vim界面
        • 谁可以使用 允许使用的主机=(以谁的身份) 可执行命令的列表
        • linuxprobe ALL=(ALL) ALL
        • ALL 意思是:某个普通用户拥有整个系统中所有命令的最高执行权

             

Guess you like

Origin www.cnblogs.com/Black-cat0987/p/12046665.html
Recommended