从创建文件说起: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. MyBatis 中#{}与${}绑定参数的区别

    MyBatis 中#{}与${}绑定参数的区别: #{}将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号.如:order by #{id},如果传入的值是111,那么解析成sql时的值为o ...

  2. 数据库html 数据的分句

    Python 中文分句 - CSDN博客 https://blog.csdn.net/laoyaotask/article/details/9260263 # 设置分句的标志符号:可以根据实际需要进行 ...

  3. POJ 3221 Diamond Puzzle.

    ~~~~ 题目链接:http://poj.org/problem? id=3221 显然是BFS找最优解.但是终止条件不好写.看到有一仅仅队交上去一直TLE. 比赛完了看题解原来是以目标状态为起点,B ...

  4. 使用SimpleAdapter 适配器时显示网络上图片方法

    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.items_list, new String[] ...

  5. 在Sql Server触发器中判断操作是Insert还是Update还是Delete

    在Sql Server触发器中判断操作是Insert还是Update还是Delete DECLARE    @IsInsert bit,    @IsUpdate bit,    @IsDelete  ...

  6. Linux 下文本查找技巧你掌握了吗?

    前言 之前介绍过很多linux下查找相关的命令,例如<Linux中的文件查找技巧>,<find命令高级用法>,<如何查看linux中文件打开情况-lsof命令>等等 ...

  7. $P5017 摆渡车$

    problem 毒瘤\(DP\) #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef lon ...

  8. HTML--使用提交按钮,提交数据

    在表单中有两种按钮可以使用,分别为:提交按钮.重置.这一小节讲解提交按钮:当用户需要提交表单信息到服务器时,需要用到提交按钮. 语法: <input type="submit" ...

  9. query.setFirstResult(0),query.setMaxResults(4)

    query.setFirstResult(0),query.setMaxResults(1);相当于MySQL中的limit 0, 1; String hql = "FROM Forum f ...

  10. 【BZOJ1483】[HNOI2009]梦幻布丁(平衡树启发式合并+并查集)

    题目: BZOJ1483 分析: (这题码了一下午,码了近250行,但是意外跑的比本校各位神仙稍快,特写博客纪念) 首先能看出一个显然的结论:颜色段数只会变少不会变多. 我们考虑用并查集维护区间,对于 ...