用户、组、权限管理练习

用户、组管理练习

一、创建的内容:
    
    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
下一篇 2017-09-03

相关推荐

  • vim文本编辑器

    Vim文本编辑器不能单独编写二进制文件,但是可以配合xxd命令编辑二进制文件 1、文本编辑种类: 行编辑器: sed 全屏编辑器:nano, vi、vim(其是改进的vi) 其他编辑器: Gedit,一个简单的图形编辑器 Gvim,一个Vim编辑器的图形版本 2、打开文件 用法#vim  [OPTION]… FILE… +#…

    Linux干货 2016-08-15
  • Linux之函数

      Linux之函数     函数介绍函数function是由若干条shell命令组成的语句块,实现代码重用和模块化编程。它与shell程序形式上是相似的,不同的是它不是一个单独的进程,不能独立运行,而是shell程序的一部分。函数和shell程序比较相似,区别在于:Shell程序在子Shell中运行而Shell函数在…

    Linux干货 2016-08-25
  • 第九周-Shell脚本编程

      1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash nologin=0 login=0 for i in `cut -d : -f 7 /etc/passwd`;do if [ $i = /sbin/n…

    Linux干货 2017-08-23
  • 马哥教育网络班21期第3周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | cut -d" " -f 1 |sort |uniq 2、取出最后登录到当前系统的用户的相关信息。 last | head -…

    Linux干货 2016-07-29
  • httpd服务归纳:httpd简介与基本安装

    一、httpd 简介  1. httpd 历史: httpd daemon 最早诞生于1995年二月, 伊利诺伊大学香槟分校的美国国家超级计算应用中心(NCSA),由Rob McCool开发。当这个项目完成后,Rob 老兄离开RCSA以后,这个项目组就解散了,这个项目也随之终止。 但是,由Brian Behlendorf 和 Cliff …

    Linux干货 2015-05-07
  • Linux进程查看与管理命令总结

    Linux进程查看与管理命令总结 内核的功能: 进程管理 文件系统 网络功能 内存管理 驱动程序 安全功能 Process:运行中程序的一个副本。(存在生命周期) Linux内核存储进程信息的固定格式:task struct 多个任务的task struct组件的链表:task list 进程创建: init 父子关系 进程:都有其父进程创建 fork(),…

    Linux干货 2016-09-07