用户、组、权限管理练习

用户、组管理练习

一、创建的内容:
    
    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

相关推荐

  • 初学Linux之用户、组和权限

    1、用户和组管理命令 
    2、理解文件权限和默认权限 
    3、设置文件权限
    4、特殊权限 
    5、ACL

    2017-12-08
  • 常见的文本处理工具及正则表达式的相关知识

    1.cat命令使用详解 cat [option]… [file]… -A equivalent=vET -b 非空行编号 -E 行为显示$ -n 显示所有行的行号 -s 行号并压缩连续空行为一行 -T 显示tab为^M 实例:显示a文件的行号及所有控制符 2.(1)head使用详解 head -n x 显示前x行 head -c x …

    Linux干货 2016-08-07
  • 磁盘分区命令与文件系统简介

    磁盘分区命令与文件系统简介   这一次的博客是整理一下这周所学的磁盘分区fdisk与mount命令,内容不难但是比较琐碎,需要记忆的命令比较多,刚好借着博客来复习一下命令,加强一下记忆。废话不多说,开始! 首先做一下准备工作:在虚拟机上增加一个或多个磁盘,这个比较简单,在VMware虚拟机上方点虚拟机右键—>设置&#82…

    2017-08-19
  • 每日一练–8.10 脚本

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 2、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到/root/etcYYYY-mm-dd中 3、编写脚本/root/bin/disk.sh,显示当前硬盘分区中空…

    Linux干货 2016-08-15
  • awk基本用法

    一、awk介绍     awk、sed&grep都可以匹配文本,但sed和awk可以对文本进行编辑,grep则不具有此功能;sed是非交互式的流编辑器,而awk则是一门模式匹配的编程语言。awk主要用于处理匹配的文本,同时awk还支持编程语言的一些特性,如变量、函数、循环语句等。  &nbs…

    Linux干货 2016-09-21
  • 计算机网络基础

    计算机网络基础 分层的网络模型 网络发展到今天,规模很庞大,内容很复杂,不利于网络的管理和教学。网络分层可以:降低网络结构的复杂性、把各层的接口标准化、简化模块设计、确保技术的互操作性、加快发展速度以及简化教学过程。 OSI模型——国际标准:根据国际标准化组织( ISO,International Standards Orgnization)提案,计算机网络…

    Linux干货 2016-11-22