用户、组、权限管理练习

用户、组管理练习

一、创建的内容:
    
    1、组Rockets,Knicks,Cavaliers,他们的GID分别是501,540,530。
    2、用户James(theBeard),Chris(CP3),Lebron(King),Carmelo(Melo),他们的uid分别是511,512,531,541,分别属于Rockets,Rockets,Cavaliers,Knicks附加组括号内是他们的描述。
    3、明文修改James的密码为111111,其他人员下次登录时必须修改密码。
    4、将James设为附加组组管理员。
    5、查看Lebron的描述文件。
    6、将Carmelo的附加组改为Rockets并查看他的uid。
    7、将Chris的附加组改为Cavaliers。
    8、切换登陆用户为James。
    9、查看附加组非别为Rockets,Knicks,Cavaliers的用户。
二、操作过程:
1.创建groupadd组rockets,gid=501 groupadd -g

    [root@h(Brad) ~]#groupadd -g 501 Houston
    groupadd: GID ‘501’ already exists
    
2.修改gid 501的组名为Rockets
    groupmod -n

    [root@h(Brad) ~]#grep 501 /etc/group
    maxxi:x:501:
    [root@h(Brad) ~]#groupmod -n Rockets maxxi        
    [root@h(Brad) ~]#grep 501
    /etc/group                     
    Rockets:x:501:

3.创建用户或修改一个用户name=James,uid511,-c theBeard
查看其uid、gid
    明文修改密码为111111 passwd –stdin
    修改附属组为Houston Rockets

    [root@h(Brad) ~]#useradd -u 511 -g 501 -c ‘theBeard’ JameHarden
    useradd: UID 511 is not unique
    [root@h(Brad) ~]#grep 511 /etc/passwd
    gentoo:x:511:511:Gentoo Distribution:/home/gentoo:/bin/csh
    [root@h(Brad) ~]#usermod -g Rockets -l James gentoo
    [root@h(Brad) ~]#vim /etc/passwd
    James:x:511:501:theBeard:/home/gentoo:/bin/csh
    “/etc/passwd” 43L, 2050C written
    [root@h(Brad) gentoo]#usermod -md /home/James James
    [root@h(Brad) home]#ll -a /home/James
    total 28
    drwx——.  4 James James 4096 Aug 30 06:36 .
    drwxr-xr-x. 13 root  root  4096 Aug 30 21:13 ..
    -rw-r–r–.  1 James James   18 Mar 23 08:15 .bash_logout
    -rw-r–r–.  1 James James  176 Mar 23 08:15 .bash_profile
    -rw-r–r–.  1 James James  124 Mar 23 08:15 .bashrc
    drwxr-xr-x.  2 James James 4096 Nov 12  2010 .gnome2
    drwxr-xr-x.  4 James James 4096 Aug 28 17:09 .mozilla
    [root@h(Brad) home]#passwd –stdin James
    Changing password for user James.
    111111
    passwd: all authentication tokens updated successfully.
    [root@h(Brad) home]#chfn James
    Changing finger information for James.
    Name [theBeard]: Beard
    Office []: Houston
    Office Phone []: 013013
    Home Phone []: 013013
    Finger information changed.
    
2.1给组Rockets设置管理员为James gpasswd -A

    [root@h(Brad) home]#gpasswd -A James Rockets
    [root@h(Brad) home]#grep Rockets /etc/gshadow
    Rockets:!:James:James
3.useradd Chris,-c CP3,group =Rockets,uid=512
    下次登录时修改密码passwd -e

    [root@h(Brad) home]#useradd -u 512 -g 511 -G 511 -c ‘CP3’ Chris
    useradd: UID 512 is not unique
    [root@h(Brad) home]#grep 512 /etc/passwd
    huangzhong:x:512:508::/home/huangzhong:/bin/bash
    [root@h(Brad) home]#userdel -r huangzhong
    [root@h(Brad) home]#useradd -u 512 -g 501 -G 501 -c ‘CP3’ Chris
    [root@h(Brad) home]#id Chris
    uid=512(Chris) gid=501(Rockets) groups=501(Rockets)
    [root@h(Brad) home]#passwd -e Chris
    Expiring password for user Chris.
    passwd: Success
    
4.useradd Carmelo,0-c melo,group=Knicks,uid=541
    下次登录时修改密码

    [root@h(Brad) home]#groupadd -g 540 Knicks
    [root@h(Brad) home]#useradd -u 541 -g 540 -G 540 -c ‘Melo’ Carmelo
    [root@h(Brad) home]#grep 541 /etc/passwd  
    [root@h(Brad) home]#gpasswd -a Carmelo Knicks
    Adding user Carmelo to group Knicks
    [root@h(Brad) home]#passwd -e Carmelo
    Expiring password for user Carmelo.
    passwd: Success
    
5.useradd Lebron,-c King group=cavaliers,uid=531
    下次登录时修改密码

    [root@h(Brad) home]#groupadd -g 530 Cavaliers
    [root@h(Brad) home]#useradd -u 531 -g 530 -G 530 -c ‘King’ Lebron
    [root@h(Brad) home]#passwd -e Lebron
    Expiring password for user Lebron.
    passwd: Success
    [root@h(Brad) home]#gpasswd -a Lebron Cavaliers
    Adding user Lebron to group Cavaliers
    
6.查看Lebron的Comments

    [root@h(Brad) home]#grep Lebron /etc/passwd
    Lebron:x:531:530:King:/home/Lebron:/bin/bash
    
7.修改Carmelo的附加组为Rockets

    [root@h(Brad) home]#usermod -G Rockets Carmelo
    
8.id看看Carmelo的uid

    [root@h(Brad) home]#id -u Carmelo
    541
    
9.指定chris加入组Cavaliers groupmems -a

    [root@h(Brad) home]#usermod -g 530 -G 530 Chris 
    
10.登录式切换用户为James

    [root@h(Brad) home]#su – James
    [James@Centos69 ~]$
    
11.显示组Rockets、Knicks、Cavaliers的用户

    [root@h(Brad) James]#groupmems -g Rockets -l
    bash: groupmems: command not found
    [root@h(Brad) James]#^C
    [root@h(Brad) James]#exit
    exit
    [James@Centos69 ~]$ exit
    logout
    [root@h(Brad) home]#groupmems -g Rockets -l
    James  Carmelo
    [root@h(Brad) home]#groupmems -g Cavaliers -l
    Lebron  Chris 
    [root@h(Brad) home]#groupmems -g Knicks -l
提示:    
su     只能切换到管理员用户权限,不使用管理员登录脚本和搜索路径;

su –   不仅切换到管理员用户权限,还使用管理员登录脚本和搜索路径。
    

三、练习2:

创建下面的用户、组和组成员关系
1、名字为admins 的组

    [root@h(Brad) home]#groupmod -n admins administrators
    用户natasha,使用admins 作为附属组
    [root@h(Brad) home]#useradd -G admins natasha
    [root@h(Brad) home]#id natasha
    uid=542(natasha) gid=542(natasha) groups=542(natasha),512(admins)

2、用户harry,也使用admins 作为附属组

    [root@h(Brad) home]#useradd -G admins harry
    [root@h(Brad) home]#id harry
    uid=543(harry) gid=543(harry) groups=543(harry),512(admins)
3、用户sarah,不可交互登录系统,且不是admins 的成员,

    [root@h(Brad) home]#useradd -s /sbin/nologin sarah
    natasha,harry,sarah密码都是centos
    [root@h(Brad) home]#passwd natasha
    Changing password for user natasha.
    New password: 
    Retype new password: 
    passwd: all authentication tokens updated successfully.
    [root@h(Brad) home]#passwd –stdin harry
    Changing password for user harry.
    centos
    passwd: all authentication tokens updated successfully.
    [root@h(Brad) home]#echo centos |passwd –stdin sarah
    Changing password for user sarah.
    passwd: all authentication tokens updated successfully.
四、权限配置练习:
    如下文件
    
    [root@h(Brad) home]#ll -a guanyu
    total 36
    drwx——.  4 guanyu guanyu 4096 Aug 30 08:39 .
    drwxr-xr-x. 18 root   root   4096 Aug 30 22:56 ..
    -rw-r–r–.  1 guanyu root      7 Aug 30 10:52 1.txt
    -rw-r–r–.  1 root   root      0 Aug 30 08:39 2.txt

1.chgrp命令修改1.txt文件所属的组为“shu”

    [root@h(Brad) home]#chgrp shu /home/guanyu/1.txt
    [root@h(Brad) home]#ll -a guanyu                   
    total 36
    drwx——.  4 guanyu guanyu 4096 Aug 30 08:39 .
    drwxr-xr-x. 18 root   root   4096 Aug 30 22:56 ..
    -rw-r–r–.  1 guanyu shu       7 Aug 30 10:52 1.txt

2.chown命令修改2.txt属于guanyu,所属组为shu

    [root@h(Brad) home]#chown guanyu:shu guanyu/2.txt
    [root@h(Brad) home]#ll -a guanyu                   
    total 36
    drwx——.  4 guanyu guanyu 4096 Aug 30 08:39 .
    drwxr-xr-x. 18 root   root   4096 Aug 30 22:56 ..
    -rw-r–r–.  1 guanyu shu       7 Aug 30 10:52 1.txt
    -rw-r–r–.  1 guanyu shu       0 Aug 30 08:39 2.txt

3.chmod命令修改2.txt的权限分别为User-read,write,execute,Group-read,execute,Others-0。

    [root@h(Brad) home]#chmod 0754 guanyu/2.txt
    [root@h(Brad) home]#ll -a guanyu           
    total 36
    drwx——.  4 guanyu guanyu 4096 Aug 30 08:39 .
    drwxr-xr-x. 18 root   root   4096 Aug 30 22:56 ..
    -rw-r–r–.  1 guanyu shu       7 Aug 30 10:52 1.txt
    -rwxr-xr–.  1 guanyu shu       0 Aug 30 08:39 2.txt

原创文章,作者:manbinn,如若转载,请注明出处:http://www.178linux.com/86146

(0)
manbinnmanbinn
上一篇 2017-09-03 19:46
下一篇 2017-09-03 21:11

相关推荐

  • Shell脚本编程3

    Shell脚本编程3  一、杂项知识整理 1、select与case select是个无限循环,因此要记住用break命令退出循环,或用exit命令终止脚本。也可以按ctrl+c退出循环,自动生成数字的选择项,适合创建菜单。 select经常和case联合使用。与for循环类似,可以省略in LIST,此时使用位置参量$1、$2等传递参数。 cas…

    Linux干货 2016-08-19
  • vim编辑器

    vim编辑器 vi:Vistual Interface,是一种文本编辑器,所谓文本编辑器就是基于字符编码的文件,常见的编码有ASCLL编码,UNICODE编码。 vim:即vi IMproved:vi的增强版,可以使用颜色或者底线等方式来显示一些特殊信息,是模式化的编辑。 文本编辑器的种类 行编辑器:所谓行编辑器就是一行一行来编辑处理的工具,如sed 全屏编…

    Linux干货 2016-08-15
  • N22-第九周作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # declare -i count1=0 declare -i count2=0 for i in $(awk -F : '{print $7}&#03…

    Linux干货 2016-10-17
  • 初学linux遇到的问题

    1 su uername 显示的是基本格式,不是类似于[root@Centos7 ~]#,看着不知道进入到哪个目录。解决办法:在家目录下使用ls -a命令显示隐藏文件,使用nano .bash_profile命令,在那里编辑PS1=”[\u@\h \W]\\$”保存退出就好了。 疑问:为什么不在/etc/bashrc下更改呢?自答:改…

    Linux干货 2017-07-15
  • ngx_http_proxy_module

    ngx_http_proxy_module 1.proxy_pass Syntax: proxy_pass URL; Context: location, if in location, limit_except 这条指令将来是用的相当多的指令。 v  附加1:proxy_pass后面的路径不带uri时,其会将loca…

    2016-10-30
  • 马哥教育网络班21期+第6周课程练习

    请详细总结vim编辑器的使用并完成以下练习题1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; %s/^([[:space:]]{1,}.*)/#\1/s 2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行…

    Linux干货 2016-08-15