用户、组、权限管理练习

用户、组管理练习

一、创建的内容:
    
    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)
上一篇 2017-09-03 19:46
下一篇 2017-09-03 21:11

相关推荐

  • 第七周作业

    第七周 1,创建一个10G分区,并格式化为ext4文件系统;(1) 要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl;(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@www ~]# fdisk /dev/sda <————-fd…

    Linux干货 2017-09-03
  • Openssl加密解密原理+CA自建实现

     Openssl加密解密原理+CA自建实现     前言 互联网的惊人发展使企业和消费者都感到非常兴奋,它正改变着我们的生活和工作方式。但是,互联网的安全程度如何——尤其是在通过它发送机密信息时的安全性——已经成为人们关心的主要问题。随着时代的发展,加密原理也不断地在更新换代. 数据的加密目前已广泛地运用于战争,商业活…

    Linux干货 2015-05-25
  • Linux软件包安装

    Linux系统和Windows系统在软件包安装上区别很大:     软件运行环境:         API: Application Programming Interface    POSIX: P…

    Linux干货 2016-08-21
  • ThridWeek_FirstDay

    python学习笔记整理

    Linux干货 2017-10-09
  • 内核体系

    单内核体系设计、但充分借鉴了微内核设计体系的优点,为内核引入模块化机制。 内核组成部分核心,一般为bzImage,通常在/boot目录下,名称为vmlinuz-VERSION-RELEASE;: kernel: 内核 kernel object: 内核对象,一般放置于/lib/modules/VERSION-RELEASE/ [ ]: N [M]: M [*…

    Linux干货 2015-09-02
  • Linux基础概念

    一、计算机的组成及其功能。 计算机机系统由五部分组成:运算器、控制器、存储器、输入设备、输出设备,遵从冯.诺依曼体系结构。具体的功能如下 : CPU   :     运算器(处理数据)、控制器(指令控制),另有寄存器、缓存(缓冲数据,内部缓存非  常昂贵); 存储器:内存即RAM(随机访问…

    Linux干货 2016-10-09