yyyyyyyyyyyyyyyyyyyy

博客园 首页 新随笔 联系 订阅 管理
用户状态命令
常用的用户状态命令包括:whoami、id、groups、newgrp 等。
􀂄 whoami:用于显示当前用户的名称
􀂄 groups:用于显示指定用户所属的组
􀂄 id:用户显示用户身份
􀂄 newgrp:用户转换用户的当前组到指定的附加组,用户必须属于该组才可以进行
下面给出这些命令的使用举例:
# 创建一个新组staff
[root@cnetos5 ~]# groupadd staff
# 将用户crq 加入staff 附加组,并为其设置口令
[root@cnetos5 ~]# usermod -G staff crq
# 显示当前用户的名称
[root@cnetos5 ~]# whoami
root
# 显示当前用户所属的组
[root@cnetos5 ~]# groups
root bin daemon sys adm disk wheel
# 显示指定用户所属的组
[root@cnetos5 ~]# groups crq
crq : crq staff
# 显示用户当前的uid、gid和用户所属的组列表
[root@cnetos5 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),
2(daemon),3(sys),4(adm),6(disk),10(wheel)
#切换当前用户到crq(超级用户切换到普通用户无需口令),同时切换用户工作环境
[root@cnetos5 ~]# su - crq
[crq@cnetos5 ~]$
# 显示用户当前的uid、gid和用户所属的组列表
[crq@cnetos5 ~]$ id
uid=504(crq) gid=504(crq) groups=504(crq),3001(staff)
# 创建一个新文件,并查看其用户和组
[crq@cnetos5 ~]$ touch abc
[crq@cnetos5 ~]$ ll abc
-rw-rw-r-- 1 crq crq 0 Dec 19 02:13 abc
# 切换用户的当前组到指定的附加组staff
[crq@cnetos5 ~]$ newgrp staff
# 显示用户当前的uid、gid和用户所属的组列表
[crq@cnetos5 ~]$ id
uid=504(crq) gid=3001(staff) groups=504(crq),3001(staff)
# 创建一个新文件,并查看其用户和组(比较abc和xyz的组)
[crq@cnetos5 ~]$ touch xyz
[crq@cnetos5 ~]$ ll
total 0
-rw-rw-r-- 1 crq crq 0 Dec 19 02:13 abc
-rw-r--r-- 1 crq staff 0 Dec 19 02:14 xyz
# 返回上一次 crq 的登录
[crq@cnetos5 ~]$ exit
exit
# 返回上一次root的登录
[crq@cnetos5 ~]$ exit
logout
[root@cnetos5 ~]#

 

posted on 2015-04-19 04:36  xxxxxxxx1x2xxxxxxx  阅读(449)  评论(0)    收藏  举报