用户、组、权限管理练习

用户、组管理练习

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

相关推荐

  • rsyslog应用举例

    rsyslog+mysql+loganalyzer 1、yum install mariadb-server php-gd rsyslog-mysql ##连接到mysql需要的驱动程序,用来保存信息 2、登录数据库并给rsyslog赋权,设置密码,重读授权表 3、以rsyslog用户身份登录数据库,此时创建Syslog库,注意此处数据库名称要与rsyslo…

    Linux干货 2016-10-23
  • 2017全球运维技术大会第二届12大技术专场等你来!

    去年9月,InfoQ在北京主办了第二届CNUTCon全球容器技术大会,大会邀请了来自Netflix、CoreOS、Docker公司、Mesosphere、阿里巴巴、腾讯、百度、京东、携程、搜狗等公司的技术负责人,共同探讨容器相关的应用场景、技术方案以及架构演进,得到了社区的一致好评。 到今年,CNUTCon已经是第三年了,前两年我们的方向是容器,随着技术的发…

    2017-06-20
  • 集中管理利器-puppet快速入门-中

    集中管理利器-puppet快速入门-中 6.    尝试启动master puppet 启动master puppet,并确认8140端口已被监听:  #puppet返回成功,但不一定能成功启动,puppet这个功能希望能改进… 7.    目录结构 /etc/puppet/  …

    Linux干货 2015-05-04
  • 自制linux和内核编译

    自制linux和内核编译 1、分区并创建文件系统 fdisk /dev/sdb分两个必要的分区/dev/sdb1对应/boot /dev/sdb2对应根/mkfs.ext4 /dev/sdb1mkfs.ext4 /dev/sdb2 2、挂载boot mkdir/mnt/bootmount /dev/sdb1 /mnt/boot 3、安装grub grub-i…

    Linux干货 2016-09-16
  • ping命令的部分用法

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”不能打开网页时会说“你先ping网关地址192.168.1.1试试”。它通过发送ICMP ECHO_REQUEST数据包到网络主机(send ICMP ECHO_REQUEST to&nbsp…

    Linux干货 2017-07-30
  • Shell脚本基础练习

    脚本编程能力是作为运维工程师不可或缺的一项基本技能,各种系统的运维,如果完全靠命令行一条一条命令来执行,工作效率可想而知,而脚本却可以将完成一定功能的各个命令依据一定的流程控制,逻辑判断去完成某种功能,提升工作效率。学习shell脚本,光学习理论是远远不够的,所以在学习中要多多练习,下面就看一些关于shell脚本基础的练习 (1) 编写脚本/root/bin…

    2017-08-05