M20 – 1- 第三周(1):课堂练习与作业

课堂练习:

1、创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"

[root@localhost ~]# useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo
[root@localhost ~]# id gentoo
uid=1004(gentoo) gid=1004(gentoo) groups=1004(gentoo),0(root),1(bin)

2、创建下面的用户、组和组成员关系

名字为admins 的组

用户natasha,使用admins 作为附属组

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

用户sarah,不可交互登录系统,且不是admins 的成员,natasha,harry,sarah密码都是centos

[root@localhost ~]# id gentoo
uid=1004(gentoo) gid=1004(gentoo) groups=1004(gentoo),0(root),1(bin)
[root@localhost ~]# 
[root@localhost ~]# groupadd admins
[root@localhost ~]# useradd -G admins natasha
[root@localhost ~]# useradd -G admins harry
[root@localhost ~]# useradd -s /bin/nologin sarah 
[root@localhost ~]# echo "centos" |passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo "centos" |passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo "centos" |passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# groupmems -g admins -l
natasha  harry

3.1、当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作?

[root@localhost ~]# useradd xiaoming
[root@localhost ~]# mkdir -m 776 /testdir
[root@localhost ~]# touch /testdir/xiaoming.txt
[root@localhost ~]# chown xiaoming.xiaoming /testdir/xiaoming.txt
[root@localhost ~]# su - xiaoming
[xiaoming@localhost ~]$ mkdir /testdir/xiaoming
mkdir: cannot create directory ‘/testdir/xiaoming’: Permission denied
[xiaoming@localhost ~]$ ls -l /testdir/xiaoming.txt 
ls: cannot access /testdir/xiaoming.txt: Permission denied
[xiaoming@localhost ~]$ rm -rf /testdir/xiaoming.txt 
rm: cannot remove ‘/testdir/xiaoming.txt’: Permission denied
[xiaoming@localhost ~]$ echo "how are you" > /testdir/xiaoming.txt
-bash: /testdir/xiaoming.txt: Permission denied

因此用户xiaoming对/testdir目录均无任何权限。

3.2、当用户xiaoqiang对/testdir 目录无读权限时,意味着无法做哪些操作

[root@centos6 ~]# ls -dl /testdir
drwxrwx-wx 12 root root 4096 Aug  5 19:57 /testdir
[root@centos6 ~]# su - xiaoqiang
[xiaoqiang@centos6 ~]$ ls -l /testdir
ls: cannot open directory /testdir: Permission denied
[xiaoqiang@centos6 ~]$ echo "how are you" > /testdir/test.txt
[xiaoqiang@centos6 ~]$ rm -rf /testdir/test.txt
[xiaoqiang@centos6 ~]$ cd /testdir/
[xiaoqiang@centos6 testdir]$ ls
因此用户xiaoqiang对目录有写和进入目录的权限

3.3、当用户wangcai 对/testdir 目录无写权限时,该目录下的只读文件file1是否可修改和删除?

[root@centos6 ~]# ls -ld /testdir
drwxrwxr-x 12 root root 4096 Aug  5 20:22 /testdir
[root@centos6 ~]# ls -l /testdir/file1 
-rwxrwxr-- 1 root root 0 Aug  5 20:22 /testdir/file1
[root@centos6 ~]# useradd wangcai
[root@centos6 ~]# su - wangcai
[wangcai@centos6 ~]$ 
[wangcai@centos6 ~]$ id wangcai
uid=3011(wangcai) gid=3011(wangcai) groups=3011(wangcai)
[wangcai@centos6 ~]$ echo "abc" >> /testdir/file1
-bash: /testdir/file1: Permission denied
[wangcai@centos6 ~]$ rm /testdir/file1
rm: remove write-protected regular empty file `/testdir/file1'? y
rm: cannot remove `/testdir/file1': Permission denied
[wangcai@centos6 ~]$

3.4、复制/etc/fstab文件到/var/tmp下,设置文件所有者为wangcai读写权限,所属组为sysadmins组有读写权限,其他人无权限

[root@centos6 ~]# cp /etc/fstab /var/tmp/
[root@centos6 ~]# groupadd sysadmins
[root@centos6 ~]# chown wangcai.sysadmins /var/tmp/fstab 
[root@centos6 ~]# chmod 660 /var/tmp/fstab
[root@centos6 ~]# ls -l /var/tmp/fstab 
-rw-rw---- 1 wangcai sysadmins 921 Aug  5 20:31 /var/tmp/fstab

3.5、误删除了用户wangcai的家目录,请重建并恢复该用户家目录及相应的权限属性

[root@centos6 ~]# rm -rf /home/wangcai
[root@centos6 ~]# su - wangcai
su: warning: cannot change directory to /home/wangcai: No such file or directory
-bash-4.1$ exit
logout
[root@centos6 ~]# mkdir /home/wangcai
[root@centos6 ~]# cp -r /etc/skel/.[^.]* /home/wangcai/
[root@centos6 ~]# su - wangcai
[wangcai@centos6 ~]$

作业:

1、创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser
[root@localhost ~]# id testuser
uid=1234(testuser) gid=1(bin) groups=1(bin),0(root),50(ftp)
[root@localhost ~]# getent passwd testuser
testuser:x:1234:1::/testdir/testuser:/bin/csh

2、修改testuser uid:4321,主组:root,辅助组:nobody,loginname:test,home:/home/test 家数据迁移

[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -m -d /home/test testuser

3、批量创建帐号:user1…user10,uid:3000-3009,shell:/bin/csh,home:/testdir/username,passwd:usernamepass(注意家目录相关配置,使用户正常登录)

[root@centos6 ~]# cat user.txt
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/user10:/bim/csh
[root@centos6 ~]# cat passwd.txt 
user1:usernamepass
user2:usernamepass
user3:usernamepass
user4:usernamepass
user5:usernamepass
user6:usernamepass
user7:usernamepass
user8:usernamepass
user9:usernamepass
user10:usernamepass
[root@centos6 ~]# newusers user.txt 
[root@centos6 ~]# getent passwd user{1..10}
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/user10:/bin/csh
[root@centos6 ~]# getent shadow user{1..10}
user1:$6$El26Odcy7S4$b5VjVn2XhTsDygdoFN7fCfAuiCGcgf02VXJGYm10qnj./94d909pSU24Jdsi3WMxNNAVn6XsnvZ5QFq1h91K00:17018:0:99999:7:::
user2:$6$Y4PXMYWRdI/j.c$Pgvk/nJ8ncZ7HLmE99A0MJET/d.1jt/auHh.tMJ3YjFJeRloWU3.JOj8UbgFxYwCotCkn7lP/dHbGTHToqYIC.:17018:0:99999:7:::
user3:$6$j1/1Q8YOCZzfCxX/$NdH3CGdInvBnkEGt8LBhLLkLkeiQUpRMA64O8i0.T0fqEa2Wy5G7CsWDhbivo00RE6E1MzHI8A0.J3WX3P0rQ1:17018:0:99999:7:::
user4:$6$YuINr/86B$X4snXO.H2Cg4zLQgEVzIrJEhq.AzoKZOh3O5xgJEGcMgPw6pmlOCjhd.tMwjbMi7w9qPGxHI6j/3uENnv48YU/:17018:0:99999:7:::
user5:$6$/S228pttn$ixljO8TNEI1fWKO1h/j3G2WyXSr3/sb//B7qpUnBFQavSn0sKbYd92TsGL7VBU.4hnlivAARhvbSDzeUQHcwB0:17018:0:99999:7:::
user6:$6$U1oCWrUS2B/z$gZtLmxjxZBSM0i0HYTF3LnolktyT5lBTcr0oN.KSP7G2MU8MkXvig1MRi1QLVOtyaxmZ8O7kwvghz4IAfNF35.:17018:0:99999:7:::
user7:$6$2HjNN/zyh6HIl$bL6omBq0QOpDa91JUORXQYFZQKA8I0enoT6zO1yhCP9hedK4tiwT/qM7tVSpE4rjvbuoFKQ413.gCEwyQWwbY1:17018:0:99999:7:::
user8:$6$gMp80/mS3KZoXt$rqY7KLDTBr7XZC4bPiTIojaG4LvlcY9iwXY59XLoz8a5X/CBmgNPq/6aO9RrNTL.7Vb.veOopprJ9EfM3kNZv0:17018:0:99999:7:::
user9:$6$TZFCR/3J$l9Cl5wrJg/NOsNvXcdT1lYXgGOdYGhyXpB5/UjW3C6WaaN1GzAO0knEYS/2hpWoCSQvRwBHFLY4xSixL1qL9I1:17018:0:99999:7:::
user10:$6$ag9YmxePEy$yJ18/ePBDJATJm1km.tpAnHyMDLbLs4VqRoSDrQpoL80nfNQWWfPQqlaheEn5pdlp1E175eJD888yjHLcBUMb/:17018:0:99999:7:::
[root@centos6 ~]# cp -r /etc/skel/.[^.]* /testdir/user1
[root@centos6 ~]# su - user1
[user1@centos6 ~]$ 
...
其他用户也运行该命令,cp -r /etc/skel/.[^.]* /testdir/user#,即可切换到该用户下,均属于正常登陆。

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

赞 (0)
AleenAleen
上一篇 2016-08-08 16:16
下一篇 2016-08-08 16:16

相关推荐

  • shell脚本编程

    Shell脚本是包含一些命令或声明,并符合一定格式的文本文件。 程序:指令+数据 程序编程风格 过程式  以指令为中心,数据服务于指令。 对象式  以数据为中心,指令服务于数据。 Shell程序:提供了编写和能力,解释执行。 编程逻辑处理方式:           顺序执行   …

    Linux干货 2016-08-15
  • 谷歌三大核心技术(三)Google BigTable中文版

    摘要 Bigtable是一个分布式的结构化数据存储系统,它被设计用来处理海量数据:通常是分布在数千台普通服务器上的PB级的数据。Google的很多项目使用Bigtable存储数据,包括Web索引、Google Earth、Google Finance。这些应用对Bigtable提出的要求差异非常大,无论是在数据量上(从URL到网页到卫星图像)还是在响应速度上…

    Linux干货 2015-04-13
  • varnish学习总结

    什么是web cache?   Web缓存是指一个Web资源(如html页面,图片,js,数据等)存在与Web服务器和客户端(浏览器)直接的副本。缓存会根据进来的请求保存输出内容的副本;当下一个请求到来的时候,如果是相同的URL,缓存会根据缓存机制决定是直接使用副本响应访问请求还是向源服务器再次发送请求。       …

    Linux干货 2015-07-15
  • N26-第八周作业-邢岩

    马哥门徒-N26-邢岩 1、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态;      在线的主机使用绿色显示;      不在线的主机使用红色显示; #!/bin/bash # Author: jeque# Des…

    2017-03-24
  • shell脚本语言的for循环使用方法和案例

    在shell语言中bash是用的最多的,其语法简单。以指令为核心快速解决常用的问题。所有语言中逻辑控制是必不可少的,它可以帮助我们减少不必要的重复性工作。今天我们就来说说所有语言都会使用的神奇的for循环,学了它以后不仅知道如果规避重复的工作,还能理解程序的运行原理。         for循环是什么?&nb…

    Linux干货 2017-04-16
  • Linux运维之进程管理

    一、进程概念 进程是内核的一个功能,在Linux中,运行一个程序或命令可以出发一个事件而驱动一个PID,在linux系统中,系统只识别二进制程序文件,我们可以通过执行系统上的二进制程序来运行程序,进而产生进程。在linux系统中第一个进程是init程序,它是系统开机第一个加载的程序,用来支撑系统的正常运行的一个程序,内核启动的一个用户级进程。   …

    Linux干货 2016-09-09