一、创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"
user gentoo -G bin,root -s /bin/csh -c 'Gentoo Distribution'
[root@centos7 ~]#useradd gentoo -G bin,root -s /bin/csh -c 'Gentoo Distribution'
[root@centos7 ~]#id gentoo
uid=1002(gentoo) gid=1002(gentoo) groups=1002(gentoo),0(root),1(bin)
[root@centos7 ~]#getent passwd gentoo
gentoo:x:1002:1002:Gentoo Distribution:/home/gentoo:/bin/csh
二、创建下面的用户、组和组成员关系
1. 名字为admins 的组
groupadd admins
[root@centos7 ~]#groupadd admins
[root@centos7 ~]#getent group admins
admins:x:1003:natasha
2. 用户natasha,使用admins 作为附属组
useradd natasha -G admins
[root@centos7 ~]#useradd natasha -G admins
[root@centos7 ~]#id natasha
uid=1003(natasha) gid=1004(natasha) groups=1004(natasha),1003(admins)
3. 用户harry,也使用admins 作为附属组
useradd harry -G admins
[root@centos7 ~]#useradd harry -G admins
[root@centos7 ~]#id harry
uid=1004(harry) gid=1005(harry) groups=1005(harry),1003(admins)
4. 用户sarah,不可交互登录系统,且不是admins 的成员
useradd sarah -s /sbin/nologin
[root@centos7 ~]#useradd sarah -s /sbin/nologin
[root@centos7 ~]#getent passwd sarah
sarah:x:1005:1006::/home/sarah:/sbin/nologin
5. natasha,harry,sarah密码都是centos
echo "centos" | passwd --stdin USERNAME
[root@centos7 ~]#echo "centos" | passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]#echo "centos" | passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]#echo "centos" | passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.