Chapter 6. Security

Presenter Notes

本节幻灯片

Unit objectives

  • Users and groups
  • Advanced file permissions

Presenter Notes

Users and Groups

  • Users:

    • Unique name
    • Unique ID (UID)
    • Password
    • File ownership is determined by user ID
  • Groups:

    • Unique name
    • Unique ID (GID)
    • Users who need access to the same files

Presenter Notes

Linux 的多用户、多任务; 有时可能是很多用户同时用同一个系统,但并不所有的用户都一定都要做同一件事,所以这就有多用户多任务之说; 举个例子,比如LinuxSir.Org 服务器,上面有FTP 用户、系统管理员、web 用户、常规普通用户等,在同一时刻,可能有的弟兄正在访问论坛;有的可能在上传软件包管理子站,比如luma 或Yuking 兄在管理他们的主页系统和FTP ;在与此同时,可能还会有系统管理员在维护系统;浏览主页的用的是nobody 用户,大家都用同一个,而上传软件包用的是FTP用户;管理员的对系统的维护或查看,可能用的是普通帐号或超级权限root帐号;不同用户所具有的权限也不同,要完成不同的任务得需要不同的用户,也可以说不同的用户,可能完成的工作也不一样;

User hierarchy

  • root

    • Super user
    • File permissions do not apply for root
    • Can do anything except the obvious
    • Account for the system administrator
  • bin, daemon, lp, sync, news, ftp ...

    • User accounts used by different applications and daemons
    • Cannot (and should not) be used to log in
  • Ordinary user accounts

Presenter Notes

管理用户(user)的工具或命令; useradd 注:添加用户 adduser 注:添加用户 passwd 注:为用户设置密码 usermod 注:修改用户命令,可以通过usermod 来修改登录名、用户的家目录等等; pwcov 注:同步用户从/etc/passwd 到/etc/shadow pwck 注:pwck是校验用户配置文件/etc/passwd 和/etc/shadow 文件内容是否合法或完整; pwunconv 注:是pwcov 的立逆向操作,是从/etc/shadow和 /etc/passwd 创建/etc/passwd ,然后会删除 /etc/shadow 文件; finger 注:查看用户信息工具 id 注:查看用户的UID、GID及所归属的用户组 chfn 注:更改用户信息工具 su 注:用户切换工具 sudo 注:sudo 是通过另一个用户来执行命令(execute a command as another user),su 是用来切换用户,然后通过切换到的用户来完成相应的任务,但sudo 能后面直接执行命令,比如sudo 不需要root 密码就可以执行root 赋与的执行只有root才能执行相应的命令;但得通过visudo 来编辑/etc/sudoers来实现; visudo 注:visodo 是编辑 /etc/sudoers 的命令;也可以不用这个命令,直接用vi 来编辑 /etc/sudoers 的效果是一样的; sudoedit 注:和sudo 功能差不多;

Groups

  • A group is a set of users, all of whom need access to a given set of files. Every user is a member of at least one group and can be a member of several groups.
  • Primary group: Used for file/directory creation
  • Group set: Used to determine access permissions
  • The user has access to files in all of the groups in its group set. The groups command shows all the groups a user is member of.

Presenter Notes

用户组(group)就是具有相同特征的用户(user)的集合体;比如有时我们要让多个用户具有相同的权限,比如查看、修改某一文件或执行某个命令,这时我们需要用户组,我们把用户都定义到同一用户组,我们通过修改文件或目录的权限,让用户组具有一定的操作权限,这样用户组下的用户对该文件或目录都具有相同的权限,这是我们通过定义组和修改文件的权限来实现的;

User Private Groups

  • Scheme where every user has its own private group as primary group, instead of one big, generic group of which everyone is member

  • Advantages: Easier to give users access to home directories of other users (for example: secretary to boss' home directory)

  • Disadvantages: Requires changes to authorization subsystem (for example: umask, useradd, ...)
  • RHEL/Fedora uses User Private Groups, SLES does not

Presenter Notes

为了使传统UNIX用户组更易于使用,红帽子LINUX使用了一种叫做私有用户组(UPG) 的模式。私有用户组模式并不改变以往UNIX处理组的任一环节。它仅仅提供了一种新 的管理用户组的方式。您一旦创建了一个新用户,默认的就会拥有一个唯一的用户组。

Advanced File permissions

SUID

  • For file: Program runs with effective user ID of owner
  • For directory: No effect

Presenter Notes

  • Set UID SUID的限制与功能: 1)SUID权限仅仅对二进制(binary program)有效 2)执行者对于该程序有x权限 3)该权限仅仅在执行该程序是有效(run-time) 4)执行者将被赋予owner的权限 举个例子,这就像皇帝的尚方宝剑、执剑者有皇帝的权利,但是这仅仅是尚方宝剑在他手里的时间里。 linux中的passwd就是最好的例子,它被设置了SUID、普通用户也可以改密码。 注意在设置时如果该文件有x 使用ls -l查看在owner的权限为上为小写的s 如果没有,则为S。 设置的方法: chmod u+s 文件

Advanced File permissions

SGID

  • For file: Program runs with effective group ID of owner
  • For directory: Files created in directory inherit the same group ID as the directory

Presenter Notes

  • SGID 与suid不同,SGID可以对目录或文件设置: 如果是对文件设置SGID他的功能和限制如下, 1)SGID权限对二进制(binary program)有效 2)执行者对于该程序有x权限 3)该权限仅仅在执行该程序是有效(run-time) 4)执行者将被赋予group的权限 /usr/bin/locate就是个例子 如果是对目录设置SGID他的工能和限制如下、 1)用户若对此目录具有r与x的权限是,该用户能够进入目录 2)用户在此目录下的有效组(effective group)将会变成改目录的group 3)用途:若用户在此目录下具有w权限,则使用者所新建的文件其group将变成该目录的group 4)SGID对于团队项目开发来说是非常有用的设置的方法: chmod g+s

Advanced File permissions

Sticky bit

  • For file: No effect
  • For directory: Only the owner of the file and the owner of the directory may delete files in this directory

Presenter Notes

  • Sticky Bit SBIT目前只对目录有效,对文件无效。他的作用: 当多个用户对于此目录具有w、x权限,用户新建的文件或目录只有root有权利删除,即,其他用户只能对自己的文件进行del、rename、move等动作,而无法删除其他人的文件。 系统中的/tmp就是这样一个目录

设置的方法: chmod o+t

Changing permissions

  • Setting file permissions is done with the chmod command

    # chmod 1755 (or o+t) commondir
    # chmod 2755 (or g+s) myprog
    # chmod 4755 (or u+s) passwd

Presenter Notes

Linux文件的三种身份和四种权限,三种身份分别为: u:文件的拥有者 g:文件所属的群组 o:其他用户 对于每个身份,又有四种权限,分别为: r:读取文件的权限(read) w:写入文件的权限(write) x:执行的权限(execute) s:特殊权限 e.g.将755换算成字符形式,为rwxr-xr-x,也就是说文件的拥有者、所属群组以及其他用户都可以读取与运行这个文件,但是只有拥有者自己可以写入这个文件

Unit summary

  • Users and groups
  • Advanced file permissions

Presenter Notes

References

  • Unit 14: User administration , Linux System Administration I: Implementation , ERC 7.2, IBM
  • Unit 15: User-level security , Linux System Administration I: Implementation , ERC 7.2, IBM

Presenter Notes