RHCE7学习笔记5——管理用户和用户组

时间:2015-01-01 06:49:00   收藏:0   阅读:372

1、用户和用户组

        /etc/passwd 文件记录了所有用户的相关信息

[root@clz ~]# 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

    技术分享

[root@clz ~]# passwd --help
Usage: passwd [OPTION...] <accountName>
  -k, --keep-tokens       keep non-expired authentication tokens
  -d, --delete            delete the password for the named account (root only)
  -l, --lock              lock the password for the named account (root only)
  -u, --unlock            unlock the password for the named account (root only)
  -e, --expire            expire the password for the named account (root only)
  -f, --force             force operation
  -x, --maximum=DAYS      maximum password lifetime (root only)密码使用最大天数
  -n, --minimum=DAYS      minimum password lifetime (root only)密码使用最少天数
  -w, --warning=DAYS      number of days warning users receives before password expiration (root only)    密码更换前警告的天数
  -i, --inactive=DAYS     number of days after password expiration when an account becomes disabled (root only)账号被取消激活前的天数,如果该值设置未负值,则表示账号不锁定,但是登陆时一定要修改密码;
  -S, --status            report password status on the named account (root only)
  --stdin                 read new tokens from stdin (root only)
[root@clz ~]# chage --help
Usage: chage [options] LOGIN

Options:
  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY 修改密码的时间戳
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE密码过期日期
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE 账号被取消激活前的天数
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS 密码最少使用天数
  -M, --maxdays MAX_DAYS        set maximim number of days before password
                                change to MAX_DAYS密码最大使用天数
  -R, --root CHROOT_DIR         directory to chroot into
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS密码更换前警告的天数


 

    技术分享



     添加用户:useradd/adduser

    
[root@clz ~]# useradd --helpOptions:
  -c, --comment COMMENT         GECOS field of the new account 全称
  -d, --home-dir HOME_DIR       home directory of the new account 家目录
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account 主组
  -G, --groups GROUPS           list of supplementary groups of the new
                                account 子组
  -m, --create-home             create the user‘s home directory
  -M, --no-create-home          do not create the user‘s home directory 不创建用户家目录
  -p, --password PASSWORD        设置密码
  -s, --shell SHELL             login shell of the new account 设置SHELL
  -u, --uid UID                 user ID of the new account 指定UID

       创建用户时一般不直接指定-p设置密码,而是在创建用户后,使用echo ‘password‘|passwd --stdin username 设置密码

        修改用户属性时,也可以使用usermod,与useradd和chage的选项类似:

[root@clz ~]# usermod --help
  -c, --comment COMMENT         new value of the GECOS field 修改全称
  -d, --home HOME_DIR           new home directory for the user account修改家目录
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -p, --password PASSWORD       use encrypted password for the new password
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account


[root@clz home]# groups tom
tom : tom
[root@clz tom1]# usermod -a -G wheel tom
[root@clz tom1]# groups tom
tom : tom wheel
[root@clz tom1]# gpasswd --help
  -a, --add USER                add USER to GROUP
  -d, --delete USER             remove USER from GROUP 将用户删除某个组
  -r, --remove-password         remove the GROUP‘s password
  -R, --restrict                restrict access to GROUP to its members
  -M, --members USER,...        set the list of members of GROUP

         用户的默认的登陆时间属性在/etc/login.defs

        技术分享

       

     组的管理:userdel删除组,添加组 groupadd

    

本文出自 “平凡之路” 博客,请务必保留此出处http://linjohn.blog.51cto.com/1026193/1598208

原文:http://linjohn.blog.51cto.com/1026193/1598208

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!