Python全栈开发S5第5天作业

作业一:

1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”

  [[email protected] ~]# vim /etc/passwd

  按‘a’进入编辑状态,修改如下

  natasha:x:1000:555:master:/home/natasha:/bin/bash

  按‘Esc’,后输入‘:wq!’退出

  或: [[email protected] ~]# useradd -u 1000 -g 555 -c master natasha

2) 修改natasha用户的家目录为/Natasha

  按‘a’进入编辑状态,修改如下

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

  按‘Esc’,后输入‘:wq!’退出

  或:[[email protected] ~]# usermod -d Natasha natasha

3) 查看用户信息配置文件的最后一行

  [[email protected] ~]# vim /etc/passwd

  [[email protected] ~]# tail -1 /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

4) 为natasha用户设置密码“123”

  [[email protected] ~]# echo ‘123‘ | passwd --stdin natasha

  Changing password for user natasha.

  passwd: all authentication tokens updated successfully.

5) 查看用户密码配置文件的最后一行

  [[email protected] ~]# tail -1 /etc/shadow

  natasha:$1$DYh6oru/$QS9PA88Smpx.vrscOkmts/:17310:0:99999:7:::

6) 将natasha用户账户锁定

  [[email protected] ~]# vim /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

  改为:natasha:x:1000:555:master:/home/Natasha:/sbin/nologin

  或:[[email protected] ~]#usermod –L natasha

7) 将natasha用户账户解锁

  [[email protected] ~]# vim /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/sbin/nologin

  改为:natasha:x:1000:555:master:/home/Natasha:/bin/bash

  或:[[email protected] ~]#usermod –U natasha

8) 新建组police,gid为999

  [[email protected] ~]# groupadd -g 999 police

  groupadd: GID ‘999‘ already exists

  [[email protected] ~]# groupadd -g 9999 police

9) 查看组配置文件的最后一行

  [[email protected] ~]# tail -1 /etc/group

  police:x:9999:

10) 将natasha用户加入police组

  [[email protected] ~]# usermod -g police natasha

11) 修改police组的组名为jingcha

  [[email protected] ~]#usermod –L natasha

  police:x:9999:natasha

  改为:jingcha:x:9999:natasha

或:[[email protected] ~]#groupmod -n jingcha police

12) 删除natasha用户,连家目录和邮箱一起删除

  [[email protected] ~]# userdel -r natasha

  userdel: group natasha not removed because it is not the primary group of user natasha.

  userdel: /var/spool/mail/natasha not owned by natasha, not removing

  userdel: natasha home directory (/home/Natasha) not found

  [[email protected] ~]# userdel -rf natasha

  userdel: user ‘natasha‘ does not exist

13) 删除jingcha组

  [[email protected] ~]# groupdel jingcha

作业二:

1) 在用户的主目录下创建目录test,进入test创建空文件file1

  [[email protected] ~]# cd ~

  [[email protected] ~]# mkdir test

  [[email protected] ~]# touch test/filel

2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组

  [[email protected] ~]# ll test/filel

  -rw-r--r--. 1 root root 0 May 24 01:49 test/filel

3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。

  [[email protected] ~]# chmod o=w test/filel

4) 查看设置结果

  [[email protected] ~]# ll test/filel

  -rw-r---w-. 1 root root 0 May 24 01:49 test/filel

5) 取消同组用户对文件file1的读取权限,并查看设置结果。

  [[email protected] ~]# chmod g=- test/filel

  [[email protected] ~]# ll test/filel

  -rw-----w-. 1 root root 0 May 24 01:49 test/filel

6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。

  [[email protected] ~]# chmod 755 test/filel

  [[email protected] ~]# ll test/filel

  -rwxr-xr-x. 1 root root 0 May 24 01:49 test/filel

7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。

  [[email protected] ~]# chmod 400 test/filel

  [[email protected] ~]# ll test/filel

  -r--------. 1 root root 0 May 24 01:49 test/filel

8) 回到上层目录,查看test的权限

  [[email protected] ~]# cd /root/test

  [[email protected] test]# ll test

  ls: cannot access test: No such file or directory

  [[email protected] test]# cd -

  /root

  [[email protected] ~]# ll -d test

  drwxr-xr--. 2 root root 19 May 24 01:49 test

9) 为其他用户添加对此目录的写权限

  [[email protected] ~]# chmod o+w test

  [[email protected] ~]# ll -d test

  drwxr-xrw-. 2 root root 19 May 24 01:49 test

作业三:

以操作文件的方式,新建一个用户alex

作业四:

1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777

  [[email protected] ~]# mkdir -p /test/dir/

  [[email protected] ~]# useradd tom

  [[email protected] ~]# groupadd group1

  [[email protected] ~]# chown tom:group1 /test/dir/

  [[email protected] ~]# chmod 777 /test/dir/

  [[email protected] ~]# ll -d /test/dir/

  drwxrwxrwx. 2 tom group1 6 May 24 02:33 /root/test/dir/

2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)

  [[email protected] ~]# useradd jack

  [[email protected] ~]# su - jack

  [[email protected] ~]$ su - root

  Password:

  Last login: Tue May 23 19:04 PDT 2017 on :0

  [[email protected] ~]# chomd o+w /test/dir/

3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)

  [[email protected] ~]# usermod -g group1 jack

  [[email protected] ~]# exit

  [[email protected] ~]$ su - root

  Password:

  [[email protected] ~]# id jack

  uid=1005(jack) gid=1006(group1) groups=1006(group1)

  [[email protected] dir]$ ll -d  /test/dir

  drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir

  [[email protected] dir]$ touch cd /test/dir

  touch: cannot touch ‘cd’: Permission denied

  [[email protected] dir]$ cd /test/dir

4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)

  [email protected] ~]# su - tom

  Last login: Wed May 24 05:08:04 PDT 2017 on pts/0

  [[email protected] ~]$ ll -d /test/dir/

  drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir/

  [[email protected] ~]$ touch  /test/dir/tom.txt

  touch: cannot touch ‘/test/dir/tom.txt’: Permission denied

  [[email protected] ~]$ cd  /test/dir/

  [[email protected] dir]$ su - root

  Password:

  Last login: Wed May 24 05:13:00 PDT 2017 on pts/0

  [[email protected] ~]# chmod o+w /test/dir

5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777

  [[email protected] dir]$ touch  /test/dir/tom.txt

  [[email protected] dir]$ touch  /test/dir/tom.txt

  [[email protected] dir]$ chown -R tom:group1 /test/dir/tom.txt

  chown: changing ownership of ‘/test/dir/tom.txt’: Operation not permitted

  [[email protected] dir]$ su - root

  Password:

  Last login: Wed May 24 05:35:36 PDT 2017 on pts/1

  [[email protected] ~]# chown -R tom:group1 /test/dir/tom.txt

  [[email protected] ~]# su - tom

  Last login: Wed May 24 05:31:40 PDT 2017 on pts/0

  [[email protected] ~]$ chmod 777 /test/dir/tom.txt

6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)

7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)

8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)

作业五:

1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”

  [[email protected] ~]# vim /etc/passwd

  按‘a’进入编辑状态,修改如下

  natasha:x:1000:555:master:/home/natasha:/bin/bash

  按‘Esc’,后输入‘:wq!’退出

  或: [[email protected] ~]# useradd -u 1000 -g 555 -c master natasha

2) 修改natasha用户的家目录为/Natasha

  按‘a’进入编辑状态,修改如下

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

  按‘Esc’,后输入‘:wq!’退出

  或:[[email protected] ~]# usermod -d Natasha natasha

3) 查看用户信息配置文件的最后一行

  [[email protected] ~]# vim /etc/passwd

  [[email protected] ~]# tail -1 /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

4) 为natasha用户设置密码“123”

  [[email protected] ~]# echo ‘123‘ | passwd --stdin natasha

  Changing password for user natasha.

  passwd: all authentication tokens updated successfully.

5) 查看用户密码配置文件的最后一行

  [[email protected] ~]# tail -1 /etc/shadow

  natasha:$1$DYh6oru/$QS9PA88Smpx.vrscOkmts/:17310:0:99999:7:::

6) 将natasha用户账户锁定

  [[email protected] ~]# vim /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/bin/bash

  改为:natasha:x:1000:555:master:/home/Natasha:/sbin/nologin

  或:[[email protected] ~]#usermod –L natasha

7) 将natasha用户账户解锁

  [[email protected] ~]# vim /etc/passwd

  natasha:x:1000:555:master:/home/Natasha:/sbin/nologin

  改为:natasha:x:1000:555:master:/home/Natasha:/bin/bash

  或:[[email protected] ~]#usermod –U natasha

8) 新建组police,gid为999

  [[email protected] ~]# groupadd -g 999 police

  groupadd: GID ‘999‘ already exists

  [[email protected] ~]# groupadd -g 9999 police

9) 查看组配置文件的最后一行

  [[email protected] ~]# tail -1 /etc/group

  police:x:9999:

10) 将natasha用户加入police组

  [[email protected] ~]# usermod -g police natasha

11) 修改police组的组名为jingcha

  [[email protected] ~]#usermod –L natasha

  police:x:9999:natasha

  改为:jingcha:x:9999:natasha

  或 :[[email protected] ~]#groupmod -n jingcha police

12) 删除natasha用户,连家目录和邮箱一起删除

  [[email protected] ~]# userdel -r natasha

  userdel: group natasha not removed because it is not the primary group of user natasha.

  userdel: /var/spool/mail/natasha not owned by natasha, not removing

  userdel: natasha home directory (/home/Natasha) not found

  [[email protected] ~]# userdel -rf natasha

  userdel: user ‘natasha‘ does not exist

13) 删除jingcha组

  [[email protected] ~]# groupdel jingcha

作业六:

1) 在用户的主目录下创建目录test,进入test创建空文件file1

  [[email protected] ~]# cd ~

  [[email protected] ~]# mkdir test

  [[email protected] ~]# touch test/filel

2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组

  [[email protected] ~]# ll test/filel

  -rw-r--r--. 1 root root 0 May 24 01:49 test/filel

3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。

  [[email protected] ~]# chmod o=w test/filel

4) 查看设置结果,

  [[email protected] ~]# ll test/filel

  -rw-r---w-. 1 root root 0 May 24 01:49 test/filel

5) 取消同组用户对文件file1的读取权限,并查看设置结果。

  [[email protected] ~]# chmod g=- test/filel

  [[email protected] ~]# ll test/filel

  -rw-----w-. 1 root root 0 May 24 01:49 test/filel

6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。

  [[email protected] ~]# chmod 755 test/filel

  [[email protected] ~]# ll test/filel

  -rwxr-xr-x. 1 root root 0 May 24 01:49 test/filel

7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。

  [[email protected] ~]# chmod 400 test/filel

  [[email protected] ~]# ll test/filel

  -r--------. 1 root root 0 May 24 01:49 test/filel

8) 回到上层目录,查看test的权限

  [[email protected] ~]# cd /root/test

  [[email protected] test]# ll test

  ls: cannot access test: No such file or directory

  [[email protected] test]# cd -

  /root

  [[email protected] ~]# ll -d test

  drwxr-xr--. 2 root root 19 May 24 01:49 test

9) 为其他用户添加对此目录的写权限

  [[email protected] ~]# chmod o+w test

  [[email protected] ~]# ll -d test

  drwxr-xrw-. 2 root root 19 May 24 01:49 test

作业七:

以操作文件的方式,新建一个用户alex

作业八:

1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777

  [[email protected] ~]# mkdir -p /test/dir/

  [[email protected] ~]# useradd tom

  [[email protected] ~]# groupadd group1

  [[email protected] ~]# chown tom:group1 /test/dir/

  [[email protected] ~]# chmod 777 /test/dir/

  [[email protected] ~]# ll -d /test/dir/

  drwxrwxrwx. 2 tom group1 6 May 24 02:33 /root/test/dir/

2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)

  [[email protected] ~]# useradd jack

  [[email protected] ~]# su - jack

  [[email protected] ~]$ su - root

  Password:

  Last login: Tue May 23 19:04 PDT 2017 on :0

  [[email protected] ~]# chomd o+w /test/dir/

3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)

  [[email protected] ~]# usermod -g group1 jack

  [[email protected] ~]# exit

  [[email protected] ~]$ su - root

  Password:

  [[email protected] ~]# id jack

  uid=1005(jack) gid=1006(group1) groups=1006(group1)

  [[email protected] dir]$ ll -d  /test/dir

  drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir

  [[email protected] dir]$ touch cd /test/dir

  touch: cannot touch ‘cd’: Permission denied

  [[email protected] dir]$ cd /test/dir

4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)

  [email protected] ~]# su - tom

  Last login: Wed May 24 05:08:04 PDT 2017 on pts/0

  [[email protected] ~]$ ll -d /test/dir/

  drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir/

  [[email protected] ~]$ touch  /test/dir/tom.txt

  touch: cannot touch ‘/test/dir/tom.txt’: Permission denied

  [[email protected] ~]$ cd  /test/dir/

  [[email protected] dir]$ su - root

  Password:

  Last login: Wed May 24 05:13:00 PDT 2017 on pts/0

  [[email protected] ~]# chmod o+w /test/dir

5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777

  [[email protected] dir]$ touch  /test/dir/tom.txt

  [[email protected] dir]$ touch  /test/dir/tom.txt

  [[email protected] dir]$ chown -R tom:group1 /test/dir/tom.txt

  chown: changing ownership of ‘/test/dir/tom.txt’: Operation not permitted

  [[email protected] dir]$ su - root

  Password:

  Last login: Wed May 24 05:35:36 PDT 2017 on pts/1

  [[email protected] ~]# chown -R tom:group1 /test/dir/tom.txt

  [[email protected] ~]# su - tom

  Last login: Wed May 24 05:31:40 PDT 2017 on pts/0

  [[email protected]n ~]$ chmod 777 /test/dir/tom.txt

6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)

7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)

8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)

时间: 2024-08-25 13:47:05

Python全栈开发S5第5天作业的相关文章

Python全栈开发S5第1天作业

编程语言的作用及与操作系统和硬件的关系 编程语言的作用:用来定义计算机程序的形式,程序员用它来编写程序,进而控制其向计算机发出指令,使计算机完成人类布置的任务. 编程语言的作用及与操作系统和硬件的关系:程序用编程语言开发,而程序必须在操作系统上运行,即操作系统是程序的运行环境.程序不能直接控制计算机硬件,必须由程序向操作系统发出请求,通过操作系统来控制硬件. 应用程序->操作系统->硬件 应用程序:指为完成某项或多项特定工作的计算机程序,它运行在用户模式,可以和用户进行交互,具有可视的用户界面

Python全栈开发【基础三】

Python全栈开发[基础三]  本节内容: 函数(全局与局部变量) 递归 函数 一.定义和使用 函数最重要的是减少代码的重用性和增强代码可读性 1 def 函数名(参数): 2 3 ... 4 函数体 5 ... 6 返回值 函数的定义主要有如下要点: def:表示函数的关键字 函数名:函数的名称,日后根据函数名调用函数 函数体:函数中进行一系列的逻辑计算 参数:为函数体提供数据 返回值:当函数执行完毕后,可以给调用者返回数据. 总结使用函数的好处: 1.减少代码重用 2.保持一致性,易维护

Python全栈开发【第一篇】:初识Python

Python全栈开发[第一篇] 本节内容: Python 的种类 Python 的环境 Python 入门(解释器.编码.变量.input输入.if流程控制与缩进.while循环) if流程控制与while循环练习题 基本数据类型前引 Python 的种类 Cpython Python的官方版本,使用C语言实现,使用最为广泛,CPython实现会将源文件(py文件)转换成字节码文件(pyc文件),然后运行在Python虚拟机上. Jyhton Python的Java实现,Jython会将Pyth

Python全栈开发

Python全栈开发 一文让你彻底明白Python装饰器原理,从此面试工作再也不怕了. 一.装饰器 装饰器可以使函数执行前和执行后分别执行其他的附加功能,这种在代码运行期间动态增加功能的方式,称之为“装饰器”(Decorator),装饰器的功能非常强大,但是理解起来有些困难,因此我尽量用最简单的例子一步步的说明这个原理. 1.不带参数的装饰器 假设我定义了一个函数f,想要在不改变原来函数定义的情况下,在函数运行前打印出start,函数运行后打印出end,要实现这样一个功能该怎么实现?看下面如何用

Python全栈开发【基础二】

Python全栈开发[基础二] 本节内容: Python 运算符(算术运算.比较运算.赋值运算.逻辑运算.成员运算) 基本数据类型(数字.布尔值.字符串.列表.元组.字典) 编码与进制转换 Python 运算符 1.算术运算: 2.比较运算: 3.赋值运算: 4.逻辑运算:  5.成员运算: 基本数据类型 1.数字 int(整型) 1 class int(object): 2 """ 3 int(x=0) -> integer 4 int(x, base=10) -&g

python全栈开发目录

python全栈开发目录 linux命令 初识python python基础数据类型 函数编程.set.深浅拷贝 内置函数 文件操作 装饰器 迭代器和生成器 常用模块 初识类和对象 类和对象(进阶) 反射 异常处理 socket.IO多路复用 线程.进程.协程 HTML CSS JavaScript DOM文档操作 jQuery实例 web框架本质 Tornado mysql基础 mysql进阶 ..... 基本算法 递归--二分法查找 冒泡排序 更多 线程池

Python全栈开发【基础四】

Python全栈开发[基础四] 本节内容: 匿名函数(lambda) 函数式编程(map,filter,reduce) 文件处理 匿名函数 lambda表达式:对于简单的函数,存在一种简便的表示方式,即lambda表达式 1 #这段代码 2 def calc(n): 3 return n**n 4 print(calc(10)) 5 6 #换成匿名函数 7 calc = lambda n:n**n 8 print(calc(10)) 匿名函数主要是和其它函数搭配使用 举例: 1 ########

自学Python全栈开发第一次笔记

我已经跟着视频自学好几天Python全栈开发了,今天决定听老师的,开始写blog,听说大神都回来写blog来记录自己的成长. 我特别认真的跟着这个视频来学习,(他们开课前的保证书,我也写了一份,哈哈哈...)我现在是准大学生,准备学习编程,日后做一个程序员,哈哈哈.听说程序员很苦逼,不过貌似挣得也很多啊.并且我貌似也只喜欢计算机这个方面,所以我想在这个行业发光. 前些天学习了一些Linux一些命令: pwd     查看你当前所在的目录  /root=计算机/E盘 /    是根目录 cd(ch

Python 全栈开发:python列表List

列表 列表是python中经常使用的数据类型,用于存放多个值. 表现形式:在[ ]内用逗号分隔,可以存放n个任意类型的值 eg: #单一类型 users=['yangli','yite','fixd'] #多类型,列表嵌套 users=['room01',['yangli',20,'音乐'],['yite',20,'篮球'],] 列表常用方法 和 函数 方法 函数 常用的操作 eg: len(list) #len(list) 计算列表的长度 ls = ['a','b','c','d'] leng