1.新建一个名为 adminuser 的组,组 id 为40000
[root@localhost ~]# groupadd -g 40000 adminuser
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
adminuser:x:40000:
2.新建一个名为 natasha 的用户,并将 adminuser 作为其附属组
[root@localhost ~]# useradd natasha -G adminuser
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adminuser:x:40000:natasha
natasha:x:1001:
3.新建一个名为 harry 的用户,并将 adminuser 作为其附属组
[root@localhost ~]# useradd harry -G adminuser
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
adminuser:x:40000:natasha,harry
natasha:x:1001:
harry:x:1002:
4.新建一个名为 sarah 的用户,其不属于 adminuser 组,并将其 shell 设置为不可登 陆 shell / sbin / nologin
[root@localhost ~]# useradd sarah -s /shell/sbin/nologin
[root@localhost ~]# id sarah
uid=1003(sarah) gid=1003(sarah) groups=1003(sarah)
5.添加用户 maomao ,修改它的家目录为/ maomao ,要求切换 maomao 时命令提示显示正常。
[root@localhost ~]# useradd maomao -d /maomao
[root@localhost ~]# cat /etc/passwd | grep maomao
maomao:x:1001:1001::/maomao:/bin/bash
[root@localhost ~]# su maomao
[maomao@localhost root]$
6.创建std1,std2两个组,要求std1组中有三个用户
[root@localhost ~]# groupadd -g std1 1000
groupadd: invalid group ID 'std1'
[root@localhost ~]# groupadd -g std1 2000
groupadd: invalid group ID 'std1'
[root@localhost ~]# groupadd std1 -g 2000
[root@localhost ~]# groupadd std2 -g 2001
[root@localhost ~]# gpasswd -a maomao std1
Adding user maomao to group std1
[root@localhost ~]# gpasswd -a harry std1
Adding user harry to group std1
[root@localhost ~]# gpasswd -a sarah std1
Adding user sarah to group std1
[root@localhost ~]# id harry
uid=1002(harry) gid=1002(harry) groups=1002(harry),40000(adminuser),2000(std1)
[root@localhost ~]# id sarah
uid=1003(sarah) gid=1003(sarah) groups=1003(sarah),2000(std1)
[root@localhost ~]# id maomao
uid=1004(maomao) gid=1004(maomao) groups=1004(maomao),2000(std1)
7.natasha、 harry 和 sarah 三个用户的密码均设置为 glegunge 创建用户(多种方式实现)
[root@localhost ~]# passwd harry
Changing password for user harry.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd sarah
Changing password for user sarah.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd natasha
Changing password for user natasha.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#
8.新建组, shengchan , caiwu , jishu
[root@localhost ~]# groupadd shengchan
[root@localhost ~]# groupadd caiwu
[root@localhost ~]# groupadd jishu
[root@localhost ~]# cat /etc/group|grep caiwu
caiwu:x:40002:
[root@localhost ~]# cat /etc/group|grep jishu
jishu:x:40003:
[root@localhost ~]# cat /etc/group|grep shengchan
shengchan:x:40001:
9.新建用户要求如下:
* wjx 是 shengchan 组的附加用户
* liuy 是 caiwu 组的附加用户
* zxx 是 jishu 组的附加用户
*新建 admin 用户,此用户不属于以上提到的三个部门,以上用户密码设置为 redhat
[root@localhost ~]# useradd wjx -g /shengchan
useradd: group '/shengchan' does not exist
[root@localhost ~]# useradd wjx -g shengchan
[root@localhost ~]# useradd liuy -g caiwu
[root@localhost ~]# useradd zxx -g jishu
[root@localhost ~]# useradd admin
[root@localhost ~]# passwd admin
Changing password for user admin.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# id wjx
uid=1005(wjx) gid=40001(shengchan) groups=40001(shengchan)
[root@localhost ~]# id liuy
uid=1006(liuy) gid=40002(caiwu) groups=40002(caiwu)
[root@localhost ~]# id zxx
uid=1007(zxx) gid=40003(jishu) groups=40003(jishu)