从创建文件说起:useradd xiaomi           这里是创建了xiaomi用户

默认系统还会创建:/home/xiaomi   /var/mail/xiaomi        即家目录和邮箱账户,同是以下文件也会增加相关用户和密码信息:

1:  /etc/passwd  新增加一行  xiaomi:x:1004:1004::/home/xiaomi:/bin/bash      分别表示:username:passwd:uid:gid:comment:dirctory:shell

2:  /etc/shadow  新增加一行  xiaomi:!!:17948:0:99999:7:::  分别表示:username:passwd locked:最近一次修改时间:最短过期时间:最长过期时间:提前7天提醒密码过期:密码到期依然可以用:密码永不过期:保留

3:  /etc/group  新增加一行  xiaomi:x:1004:  分别表示:groupname:加密:gid:附加组

4:  /etc/gshadow  新增加一行  xiaomi:!::     分别表示:groupname:加密口令:主组:附加组

一些默认行为:

  1,密码的显示问题,可以用pwunconv和pwconv进行切换,默认是pwconv的,显示为x如下图:

    

  2,uid,gid默认60000以内递增(配置文件在/etc/login.defs),默认家目录/home/xiaomi ,默认shell为bash

  3,shadow文件存放用户的密码

  4,group文件存放了用户的主组和附加组相关信息

  5,gshadow存放了组的密码

下面执行一系列操作:

1,创建dalao组密码为dalao      命令:`groupadd dalao -p dalao`

2,创建这些用户属于dalao组:mayun,mahuateng,leijun,liyanhong, 他们的密码都是"big4"  命令:useradd -G dalao mayun  echo "big4" |passwd --stdin mayun

3,检查这几个用户的组信息  命令: id, getent group dalao, getent gshadow dalao, groups mayun等等都可以查看

======================================================分割线==================================================================

几个重要的文件:

1,/etc/login.defs    用户登录的默认的配置文件

2,/etc/passwd     用户信息存放位置

3,/etc/shadow     用户密码存放位置

4,/etc/group      组信息存放位置

5,/etc/gshadow    组密码存放位置

6,/etc/shells      系统支持的shells

7,/etc/default/useradd  创建用户名的默认设置

8,/etc/skel       目录包含的默认文件

====================================================分割线====================================================================

主要命令用法:

useradd [options] LOGIN

-u  uid

-g  gid

-G  指定附加组

-p  设置密码

-s  指定shell

-c  添加备注

-r  表明创建的的是系统用户

-d  指定家目录

usermod  修改用户信息

语法:usermod [options] LOGIN

-a  只能和-G一起使用,将用户追加到一个附加组   例如: usermod -aG alibaba mayun  将mayun添加到alibaba组

其他一些用法与useradd类似  -g  -c  -d  -e:设置过期日期  -f:设置账号到期,几天停用

userdel  删除用户

-f  强制删除用户,即使用户正在登陆状态

-r  只删除家目录,其他该用户的数据需要手工删除

=====================================================分割线==============================================================

groupadd  groupmod  groupdel  不想写了,直接查看man手册

=====================================================分割线==============================================================

其他相关命令

  chown  修改文件所属者

  chgrp  修改文件所属组

  chsh -s  修改用户shell

  chfn    修改用户描述信息

  chage    修改用户密码设置

  chmem  配置内存

  getent   可以查看用户,密码,组和组密码  例子:getent passwd xiaomi

  pwconv  密码显示为x

  pwunconv  密码显示为加密过的数据展现

  grpconv

  grpunconv  和上面一个意思

  vipw    等于 vi /etc/passwd

  vigr    等于 vi /etc/group

  pwck  检查密码文件

  grpck  检查group文件

  groupmems -a mayun -g alibaba  将马云添加到alibaba组

 ==================

最后来看看/etc/login.defs这个文件的内容,可以看到里面设置了一些默认配置。

     1  #
2 # Please note that the parameters in this configuration file control the
3 # behavior of the tools from the shadow-utils component. None of these
4 # tools uses the PAM mechanism, and the utilities that use PAM (such as the
5 # passwd command) should therefore be configured elsewhere. Refer to
6 # /etc/pam.d/system-auth for more information.
7 #
8
9 # *REQUIRED*
10 # Directory where mailboxes reside, _or_ name of file, relative to the
11 # home directory. If you _do_ define both, MAIL_DIR takes precedence.
12 # QMAIL_DIR is for Qmail
13 #
14 #QMAIL_DIR Maildir
15 MAIL_DIR /var/spool/mail
16 #MAIL_FILE .mail
17
18 # Password aging controls:
19 #
20 # PASS_MAX_DAYS Maximum number of days a password may be used.
21 # PASS_MIN_DAYS Minimum number of days allowed between password changes.
22 # PASS_MIN_LEN Minimum acceptable password length.
23 # PASS_WARN_AGE Number of days warning given before a password expires.
24 #
25 PASS_MAX_DAYS 99999
26 PASS_MIN_DAYS 0
27 PASS_MIN_LEN 5
28 PASS_WARN_AGE 7
29
30 #
31 # Min/max values for automatic uid selection in useradd
32 #
33 UID_MIN 1000
34 UID_MAX 60000
35 # System accounts
36 SYS_UID_MIN 201
37 SYS_UID_MAX 999
38
39 #
40 # Min/max values for automatic gid selection in groupadd
41 #
42 GID_MIN 1000
43 GID_MAX 60000
44 # System accounts
45 SYS_GID_MIN 201
46 SYS_GID_MAX 999
47
48 #
49 # If defined, this command is run when removing a user.
50 # It should remove any at/cron/print jobs etc. owned by
51 # the user to be removed (passed as the first argument).
52 #
53 #USERDEL_CMD /usr/sbin/userdel_local
54
55 #
56 # If useradd should create home directories for users by default
57 # On RH systems, we do. This option is overridden with the -m flag on
58 # useradd command line.
59 #
60 CREATE_HOME yes
61
62 # The permission mask is initialized to this value. If not specified,
63 # the permission mask will be initialized to 022.
64 UMASK 077
65
66 # This enables userdel to remove user groups if no members exist.
67 #
68 USERGROUPS_ENAB yes
69
70 # Use SHA512 to encrypt password.
71 ENCRYPT_METHOD SHA512
72

  

 

Linux:用户和组总结的更多相关文章

  1. linux 用户和组操作

    linux用户操作 查看登陆用户:whoami (结果最简洁) 或者who mom likes 或者who am i查看所有用户:cat /etc/passwd 添加:sudo adduser lil ...

  2. linux学习16 Linux用户和组管理命令演练和实战应用

    一.上集回顾 1.bash globing,IO重定向及管道 glob:*,?,[],[^] IO重定向: >,>>, 2>,2>> &>,& ...

  3. linux用户和组 之 用户管理

    一. linux 用户和组的基本介绍 1.linux下 有三种用户: 1. root: 权限最大的. 2. 系统用户: UID小于1000的.系统服务管理用户,一般是不允许登录系统的.(比如mysql ...

  4. Linux —用户和组

    Linux 用户和组 1.用户和组的概念 用户的作用: Authentication:认证 Authorization:授权 Accouting:审计 用户存在的最终目的: 为了实现资源的分派 组的作 ...

  5. linux用户和组管理,/etc/passwd 、/etc/shadow和/etc/group 文件内容解释

    与用户相关的系统配置文件主要有/etc/passwd 和/etc/shadow,其中/etc/shadow是用户资讯的加密文件,比如用户的密码口令的加密保存等: /etc/passwd 和/etc/s ...

  6. linux用户、组管理及权限(一)

    一.用户管理 1.为什么需要用户 1)计算机及网络资源的合理分配  2)可以控制用户访问系统的权限.3)身份认证 4) 进程 以某个用户的身份来运行 2.用户分类 用户的角色是通过UID(用户ID)来 ...

  7. linux用户及组管理

    useradd      添加用户 passwd       修改用户密码 userdel       删除用户,默认不删除用户主目录和email,如果想删除可加 –r 参数 groupadd   添 ...

  8. java程序员菜鸟进阶(十五)linux基础入门(三)linux用户和组管理

    我们大家都知道,要登录linux操作系统,我们必须要有一个用户名和密码.每一个用户都由一个惟一的身份来标识,这个标识叫做用户ID.系统中的每一个用户也至少需要属于一个"用户分组". ...

  9. Linux 用户与组的基本操作及文件权限位的设置方法

    用户的基本操作 添加用户: useradd xxx 查看所有的用户: cat /etc/passwd 用户更改组: usermod -G groups loginname 将用户从组中删除: gpas ...

  10. Linux 用户与组

    在 Linux 操作系统下,如何添加一个新用户到一个特定的组中?如何同时将用户添加到多个组中?又如何将一个已存在的用户移动到某个组或者给他增加一个组?对于不常用 Linux 的人来讲,记忆 Linux ...

随机推荐

  1. 修改this指向(bind、call 和 apply)

    一.bind 首先: var alertWrite = document.write; alertWrite('who am I?'); 这两行代码的运行结果是什么呢?不要急着回答,看完下面的内容再回 ...

  2. Spring自我总结

    1.InitializingBean Spring设置完一个bean的合作者后,会检查bean是否实现InitializingBean接口,实现的话会调用afterPropertiesSet(Init ...

  3. ALSA声卡驱动中的DAPM详解之一:kcontrol

    DAPM是Dynamic Audio Power Management的缩写,直译过来就是动态音频电源管理的意思,DAPM是为了使基于linux的移动设备上的音频子系统,在任何时候都工作在最小功耗状态 ...

  4. 第二章、Tiny4412 U-BOOT移植二 启动分析【转】

    本文转载自:http://blog.csdn.net/eshing/article/details/37521481 版权声明:本文为博主原创文章,未经博主允许不得转载. 一.启动过程说明 讲解启动过 ...

  5. Python:SMOTE算法——样本不均衡时候生成新样本的算法

    Python:SMOTE算法 直接用python的库, imbalanced-learn imbalanced-learn is a python package offering a number ...

  6. atoi函数——将字符串转换为整数

    atoi在一个叫<cstdlib>的库里,可以把字符串直接转换为整数,贼强势. 还有一个atof,就是换成浮点数,实质上是一样的. 例子: #include<cstdlib> ...

  7. Coursera Algorithms week3 快速排序 练习测验: Decimal dominants(寻找出现次数大于n/10的元素)

    题目原文: Decimal dominants. Given an array with n keys, design an algorithm to find all values that occ ...

  8. explain 详解 (转)

    原文:http://blog.csdn.net/zhuxineli/article/details/14455029 explain显示了MySQL如何使用索引来处理select语句以及连接表.可以帮 ...

  9. PCB genesis连孔加除毛刺孔(圆孔与槽孔)实现方法(二)

    一.为什么 连孔加除毛刺孔 原因是 PCB板材中含有玻璃纤维, 毛刺产生位置在于2个孔相交位置,由于此处钻刀受力不均导致纤维切削不断形成毛刺 ,为了解决这个问题:在钻完2个连孔后,在相交处再钻一个孔, ...

  10. [Swift通天遁地]二、表格表单-(14)实时调整表单元素的激活和失效

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...