红帽RHCE考试上午-RHCSA(RH200)
servera.example.com 任务
4. 创建用户账户
要求:创建下列用户、用户组,并按如下要求相关完成设置
• 用户组名为 sysmgrs
• natasha 用户的附属组是 sysmgrs
• harry 用户的附属组是 sysmgrs
• john 用户的 shell 是非交互式shell,且不是 sysmgrs 组的成员
• natasha、harry、john 的密码是 redhat
题目内容解析:
• 创建用户组需要groupadd命令操作
• 创建用户useradd命令,指定附属组时需要在创建用户的是-G指定
• 创建的用户是非交互式shell,也就是不能登入的、就可以使用/sbin/nologin
• 设置密码可以passwd命令即可
实操演示过程:
创建sysmgrs用户组
[root@servera conf]# groupadd sysmgrs
创建用户配置指定的配置
[root@servera conf]# useradd -G sysmgrs natasha
[root@servera conf]# useradd -G sysmgrs harry
[root@servera conf]# useradd -s /sbin/nologin john
命令解析:
groudadd:创建用户组
useradd:创建用户
-G:表示指定用户的附属组
-s:表示指定用户shell的解释器,也就是shell环境
注:如果在创建用户没有指定用户组时,默认是同时创建相同的用户组信息
设置指定用户的密码
方式一:设置用户的密码
[root@servera conf]# echo redhat | passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@servera conf]# echo redhat | passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@servera conf]# echo redhat | passwd --stdin john
Changing password for user john.
passwd: all authentication tokens updated successfully.
命令解析:
--stdin : 从标准输入读取令牌(只有root(根)用户才能进行此操作)
echo:打印并输出内容
或者
[root@servera conf]# id natasha && id harry && id john
uid=1000(natasha) gid=1001(natasha) groups=1001(natasha),1000(sysmgrs)
uid=1001(harry) gid=1002(harry) groups=1002(harry),1000(sysmgrs)
uid=1002(john) gid=1003(john) groups=1003(john)
方式二、密码的创建也可以是如下的操作:
样例:
[root@servera conf]# passwd john
Changing password for user john.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
或者
[root@servera html]# for i in natasha harry john; do echo redhat | passwd --stdin $i; done
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
Changing password for user harry.
passwd: all authentication tokens updated successfully.
Changing password for user john.
passwd: all authentication tokens updated successfully.
验证密码是否设置的正确
格式:su - 用户名称
注:如果是登入的是root用户,然后切换到普通用户的话,系统默认不用校验密码的