zoukankan      html  css  js  c++  java
  • 009_User and group

    1. linux security context
        Which resources a process can access depends on the user running the process.
        For example,the root user own the following file.
            -rw-------. 1 root root 1920 Aug 25 21:05 anaconda-ks.cfg
            But we want to view the file with the cat command in other users
                The owner of the file is root, so we can not access the file with the cat command by its permission of owner
                The group of the file is root, so we can not access the file with the cat command by its permission of group.
                So we can access the file by other permission.
                --------------This is linux security context
    2. The type of linux group:
        Basic group of users(the main group):
            The basic group has the same name as user:private group
        Additional group of users:
    3. The configuration files related to users and the group of users:
        /etc/passwd:users and their attributes infomations(name、UID、GID);
            name:password:UID:GID:GECOS:directory:shell
            user name:passwd:UID:GID:GECOS:home directory:default shell
        /etc/group:groups and their attributes infomations;
            group_name:password:GID:user_list
            group name:gpasswd:GID:the user list in which users use current group as their additional group (seperated by comma).
        /etc/shadow:用户密码及其相关属性;
            用户名:加密了的密码:最近一次更改密码的日期:密码的最小使用期限:最大密码使用期限:密码警告时间段:密码禁用期:账户过期日期:保留字段
        /etc/gshadow:组密码及其相关属性;
    4. 用户相关命令
        4.1 useradd : 添加用户
            [root@promote ~]# useradd user1
                上面这句命令执行后,/etc/passwd /etc/group /etc/shadow /etc/gshadow这四个文件中都添加了user1相应的内容
            -u 指明UID: 范围在[UID_MIN, UID_MAX], 而这两个值定义在/etc/login.defs
            -g GID:指明用户所属基本组,可为组名,也可以GID;
            -c "COMMENT":用户的注释信息(也就是GECOS);
            -d /PATH/TO/HOME_DIR: 以指定的路径为家目录;
            -s SHELL: 指明用户的默认shell程序,可用列表在/etc/shells文件中;
            -G GROUP1[,GROUP2,...[,GROUPN]]]:为用户指明附加组;组必须事先存在;
            -r: 创建系统用户
                CentOS 6: ID<500
                CentOS 7: ID<1000
            默认值设定:/etc/default/useradd文件中
                useradd -D
                    -s SHELL
    5. 组相关命令
        5.1 groupadd : 添加组
            -g GID: 指明GID号;[GID_MIN, GID_MAX] 而这两个值定义在/etc/login.defs
            -r: 创建系统组;
                CentOS 6: ID<500
                CentOS 7: ID<1000

    6. id : print real and effective user and group IDs
    7. su : 切换用户或以其他用户身份执行命令
        切换用户的方式:
            su UserName:非登录式切换,即不会读取目标用户的配置文件;
            su - UserName:登录式切换,会读取目标用户的配置文件;完全切换;
            Note:root su至其他用户无须密码;非root用户切换时需要密码;
            换个身份执行命令:
                su [-] UserName -c 'COMMAND'
            选项:
                -l:“su -l UserName”相当于“su - UserName”
    8. usermod : 用户属性修改
        -u UID: 新UID
        -g GID: 新基本组
        -G GROUP1[,GROUP2,...[,GROUPN]]]:新附加组,原来的附加组将会被覆盖;若保留原有,则要同时使用-a选项,表示append;
        -s SHELL:新的默认SHELL;
        -c 'COMMENT':新的注释信息;
        -d HOME: 新的家目录;原有家目录中的文件不会同时移动至新的家目录;若要移动,则同时使用-m选项;
        -l login_name: 新的名字;
        -L: lock指定用户
        -U: unlock指定用户
        -e YYYY-MM-DD: 指明用户账号过期日期;
        -f INACTIVE: 设定非活动期限;
    9. passwd : 给用户添加密码  /etc/shadow文件
        passwd [OPTIONS] UserName: 修改指定用户的密码,仅root用户权限
        passwd: 修改自己的密码;
        常用选项:
            -l: 锁定指定用户
            -u: 解锁指定用户
            -n mindays: 指定最短使用期限
            -x maxdays:最大使用期限
            -w warndays:提前多少天开始警告
            -i inactivedays:非活动期限;
            --stdin:从标准输入接收用户密码;
                echo "PASSWORD" | passwd --stdin USERNAME
    10. userdel : 删除用户 userdel [OPTION]... login
        -r: 删除用户家目录;
    11. groupmod : 组属性修改
        groupmod [OPTION]... group
            -n group_name: 新名字
            -g GID: 新的GID;
    12. groupdel : 组删除
        groupdel GROUP
    13. gpasswd : 组密码
        gpasswd [OPTION] GROUP
            -a user: 将user添加至指定组中;
            -d user: 删除用户user的以当前组为组名的附加组
            -A user1,user2,...: 设置有管理权限的用户列表
    14. newgrp命令:临时切换基本组;
        如果用户本不属于此组,则需要组密码;
    15. chage : change user password expiry information
        chage [OPTION]... LOGIN
            -d LAST_DAY
            -E, --expiredate EXPIRE_DATE
            -I, --inactive INACTIVE
            -m, --mindays MIN_DAYS
            -M, --maxdays MAX_DAYS
            -W, --warndays WARN_DAYS

  • 相关阅读:
    Beta阶段冲刺---Day1
    网络15软工个人作业5——软件工程总结
    软工网络15个人作业4——alpha阶段个人总结
    软件工程个人作业3——集大通APP案例分析
    软件工程网络15结对编程作业
    软件工程网络15个人阅读作业2-提出问题
    软工网络15个人阅读作业1
    Java课程设计—学生成绩管理系统(201521123002 林楚虹)
    201521123002《Java程序设计》第14周学习总结
    201521123002 《Java程序设计》第13周学习总结
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9600857.html
Copyright © 2011-2022 走看看