1、创建组distro,其GID为2019;

[root@Centos7 ~]# groupadd -g 2019 distro
[root@Centos7 ~]# getent group distro
distro:x:2019:

2、创建用户mandriva,其ID号为1005;基本组为distro;

[root@Centos7 ~]# useradd -u 1005 -g distro mandriva
[root@Centos7 ~]# getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
[root@Centos7 ~]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

3、创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@Centos7 ~]# useradd -u 1100 -d /home/linux mageia
[root@Centos7 ~]# getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash

[root@Centos7 ~]# ls /home/mandriva/ -dl
drwx------ 3 mandriva distro 78 Jun 29 10:29 /home/mandriva/

4、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期;

[root@Centos7 ~]# echo "mageedu" | passwd -x 7 --stdin mandriva 
Adjusting aging data for user mandriva.
passwd: Success

[root@Centos7 ~]# getent shadow mandriva
mandriva:!!:18442:0:7:7:::

[root@Centos7 ~]# chage -l mandriva 
Last password change                    : Jun 29, 2020
Password expires                    : Jul 06, 2020
Password inactive                   : never
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 7
Number of days of warning before password expires   : 7

5、删除mandriva,但保留其家目录;

[root@Centos7 ~]# userdel mandriva 
[root@Centos7 ~]# ls /home/mandriva/ -d
/home/mandriva/

6、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@Centos7 ~]# getent group peguin
[root@Centos7 ~]# groupadd peguin
[root@Centos7 ~]# getent group peguin
peguin:x:2020:

[root@Centos7 ~]# useradd -u 2002 -g distro -G peguin slackware
[root@Centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

[root@Centos7 ~]# cat /etc/group |grep distro
distro:x:2019:
[root@Centos7 ~]# cat /etc/group |grep peguin
peguin:x:2020:slackware
[root@Centos7 ~]# groupmems -g peguin -l
slackware

7、修改slackware的默认shell为/bin/tcsh;

[root@Centos7 ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/bash

[root@Centos7 ~]# usermod -s /bin/tcsh slackware 
[root@Centos7 ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh

8、为用户slackware新增附加组admins;

[root@Centos7 ~]# getent group admins
admins:x:2021:

#usermod -G是直接新增附加组,但是slackware之前就有附加组,所以会把之前的替换
[root@Centos7 ~]# usermod -G admins slackware 
[root@Centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2021(admins)

#如果不替换是追加新增附加组,是需要加上-a和-G的联合使用才行
[root@Centos7 ~]# usermod -aG peguin  slackware
[root@Centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)

[root@Centos7 ~]# groups slackware
slackware : distro peguin admins