1,创建用户user1,附加组bin和root,默认shell为/bin/bash,注释信息"user1_info"
useradd user1 -G bin,root -s /bin/bash -c "user1_info"
cat /etc/passwd
user1: x:1001:1001:user1_info:/home/user1:/bin/bash
cat /etc/group
root:x :0:user1
bin:x :1:user1
2,创建admins组
groupadd admins
[root@localhost ~]# cat /etc/group | grep admins
admins:x :1002:
3,创建用户nat ,使用admins作为附加组
useradd nat -G admins
[root@localhost ~]# cat /etc/passwd | grep nat
nat:x :1002:1003::/home/nat:/bin/bash
[root@localhost ~]# cat /etc/group | grep nat
admins:x :1002:nat
nat:x :1003:
4,创建用户harry,也使用admins作为附加组
useradd harry -G admins
5,创建用户sarah,不可交互登录系统,且不是admins组的成员
useradd sarah -s /sbin/nologin
[root@localhost ~]# cat /etc/passwd | grep sarah
sarah:x :1003:1004::/home/sarah:/sbin/nologin
6,nat,harry,sarah的密码都是centos7
echo "centos7" | passwd --stdin nat
Changing password for user nat.
passwd: all authentication tokens updated successfully.
其余两个同上
7,创建user2 uid为10000,辅助组root,hone家目录为/home/user200
useradd user2 -u 10000 -G root -d /home/user200
[root@localhost ~]# cat /etc/passwd | grep user2
user2:x :10000:10000::/home/user200:/bin/bash
[root@localhost ~]# cat /etc/group | grep user2
root:x :0:user1,user2
user2:x :10000:
8,删除user1 用户及其家目录
userdel -r user1
[root@localhost ~]# cat /etc/passwd | grep user1
[root@localhost ~]#
9,创建用户user100,并将该用户添加到group200 组中
useradd user100 -G group200
useradd: group ‘group200’ does not exist
[root@localhost ~]# groupadd group200
[root@localhost ~]# useradd user100 -G group200
[root@localhost ~]#
10,修改用户usre100 用户名为user1000
usermod -l user1000 user100
[root@localhost ~]# cat /etc/passwd | grep user100
user1000:x :10001:10002::/home/user100:/bin/bash
发现只是修改了用户家目录,用户名可用vi 进行修改
11,锁定用户user1000
usermod -L user1000
12,解锁用户user1000
usermod -U user1000