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

相关推荐

  • 文本编辑工具vim

                             vim +#: 打开文件直接处在#行 +/PATTERN:打开文件直接处在第一次匹配到行 vim + file :打开文件直接处在最后行 vim –b file :以二进制打开文件…

    Linux干货 2016-08-12
  • MySQL与nfs的实验

    (1) 创建一个共享mydata,路径为/mysql/data,客户端1挂载至/mydata;而后客户端1主机安装mysql或mariadb,将数据目录设定为/mydata,要确保mysql服务能正常 运行,但数据目录位于samba server上; (2) 客户端2主机使用类似客户端1主机的方式挂载mydata共享至本地的/mydata目录,而后,直接安装…

    Linux干货 2016-10-30
  • 用户和组管理

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@suywien ~]# who | cut -d ‘ ‘ -f1 | uniq -c 2 root [root@suywien ~]# 2、取出最后登录到当前系统的用户的相关信息。 [root@suywien ~]# who | tail -1 | cut…

    Linux干货 2018-03-18
  • 马哥教育网络班22期+第1周课程练习

    1、描述计算机的组成及其功能。     计算机由五大功能部分组成(冯诺依曼体系):运算器、控制器、储存器、输入设备、输出设备,对应到具体的硬件设备如下:     CPU    :    包含运算器、控…

    Linux干货 2016-08-15
  • Python函数式编程指南(四):生成器

    转自 http://www.cnblogs.com/huxi/archive/2011/07/14/2106863.html 生成器是迭代器,同时也并不仅仅是迭代器,不过迭代器之外的用途实在是不多,所以我们可以大声地说:生成器提供了非常方便的自定义迭代器的途径。 这是函数式编程指南的最后一篇,似乎拖了一个星期才写好,嗯…… 转载请注明原作者和原文地…

    Linux干货 2015-03-09
  • shell脚本语言的for循环使用方法和案例

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

    Linux干货 2017-04-16