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

groupadd -g 555 netasha
useradd -u 1000 -g netasha -c "master" netasha useradd -u 1000 -c "master" netasha
groupmod -g 555 netasha

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

mkdir /Netasha
usermod -d /Netasha/ netasha
tail -1 /etc/passwd

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

tail -1 /etc/passwd
tail -1 /etc/shadow
tail -1 /etc/group
tail -1 /etc/shadow

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

echo "123"|passwd --stdin netasha

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

tail -1 /etc/shadow

6) 将natasha用户账户锁定

usermod -L netasha

7) 将natasha用户账户解锁

usermod -U netasha

8) 新建组police,gid为999

groupadd -g 999 police

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

tail -1 /etc/group

10) 将natasha用户加入police组

usermod -G police netasha

11) 修改police组的组名为jingcha

groupmod netasha -n jingcha

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

userdel -r netasha
rm -rf /home/netasha

13) 删除jingcha组

groupdel jingcha

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

[root@bogon ~]# mkdir test
[root@bogon ~]# cd test/
[root@bogon test]# touch file1

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

[root@bogon ~]# ls -ld test/
drwxr-xr-x 2 root root 19 Mar 15 16:16 test/
[root@bogon test]# ls -l file1
-rw-r--r-- 1 root root 0 Mar 15 16:16 file1

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

chmod o+w file1

4) 查看设置结果,

[root@bogon test]# ll
total 4
-rw-r--r-- 1 root root 8 Mar 15 16:40 file1

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

[root@bogon test]# chmod g-r file1
[root@bogon test]# ll
total 4
-rw----rw- 1 root root 8 Mar 15 16:40 file1

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

chmod 755 file1
[root@bogon test]# ll file1
-rwxr-xr-x 1 root root 8 Mar 15 16:40 file1

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

[root@bogon test]# chmod 400 file1
[root@bogon test]# ll file1
-r-------- 1 root root 8 Mar 15 16:40 file1

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

[root@bogon test]# cd ..
[root@bogon ~]# ll -d test/
drwxr-xr-x 2 root root 19 Mar 15 16:40 test/

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

[root@bogon ~]# chmod o+w test/
[root@bogon ~]# ll -d test/
drwxr-xrwx 2 root root 19 Mar 15 16:40 test/

  

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

[root@bogon ~]# mkdir /home/alex
[root@bogon ~]# cp -r /etc/skel/.[!.]* /home/alex/
[root@bogon ~]# chown -R alex:alex /home/alex/
[root@bogon ~]# chmod 700 /home/alex/
[root@bogon ~]# ll -la /home/alex/
total 12
drwxr-xr-x 2 alex alex 62 Mar 15 17:08 .
drwxr-xr-x. 10 root root 111 Mar 15 17:08 ..
-rw-r--r-- 1 alex alex 18 Mar 15 17:08 .bash_logout
-rw-r--r-- 1 alex alex 193 Mar 15 17:08 .bash_profile
-rw-r--r-- 1 alex alex 231 Mar 15 17:08 .bashrc [root@bogon ~]# touch /var/spool/mail/alex
[root@bogon ~]# chown alex:mail /var/spool/mail/alex
[root@bogon ~]# ll /var/spool/mail/alex
-rw-r--r-- 1 alex mail 0 Mar 15 17:06 /var/spool/mail/alex [root@bogon ~]# tail -1 /etc/passwd
alex:x:1006:1006::/home/alex:/bin/bash
[root@bogon ~]# tail -1 /etc/shadow
alex:!!:17240:0:99999:7:::
[root@bogon ~]# tail -1 /etc/group
alex:x:1006:
[root@bogon ~]# tail -1 /etc/gshadow
alex:!::

作业四:

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

[root@bogon ~]# mkdir -p /test/dir
[root@bogon ~]# chown -R tom:group1 /test/dir/
[root@bogon ~]# chmod 777 /test/

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

[root@bogon ~]# useradd  jack
[root@bogon ~]# su - jack
[jack@bogon ~]$ cd /test/dir/
[jack@bogon dir]$ touch 1.txt
touch: cannot touch ‘1.txt’: Permission denied [root@bogon test]# chmod o+w dir/
[jack@bogon dir]$ touch 1.txt
touch: cannot touch ‘1.txt’: Permission denied

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

[root@bogon ~]# usermod -G group1 jack
[root@bogon ~]# chmod g+w dir/
[root@bogon ~]# su - jack
Last login: Wed Mar 15 17:22:55 CST 2017 on pts/1
[jack@bogon ~]$ cd /test/dir/
[jack@bogon dir]$ touch 1.txt
[jack@bogon dir]$ echo 123 > 1.txt
[jack@bogon dir]$ more 1.txt
123

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

[root@bogon ~]# su - tom
[tom@bogon ~]$ cd /test/dir/
[tom@bogon dir]$ touch 2.txt
[tom@bogon dir]$ echo 456 > 2.txt
[tom@bogon dir]$ cat 2.txt
456

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

[root@bogon dir]# touch tom.txt
[root@bogon dir]# chown tom:group1 tom.txt
[root@bogon dir]# chown 777 /test/

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

[root@bogon ~]# useradd rose
[root@bogon ~]# su - rose
[rose@bogon ~]$ cd /test/dir/
[rose@bogon dir]$ cat tom.txt
[rose@bogon dir]$ echo 789 > tom.txt
-bash: tom.txt: Permission denied [root@bogon dir]# chmod o+w tom.txt
[rose@bogon dir]$ echo "df -h" > tom.txt
[rose@bogon dir]$ ./tom.txt
-bash: ./tom.txt: Permission denied [root@bogon dir]# chmod o+x tom.txt
[rose@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.6M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0

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

[root@bogon ~]# usermod -G group1 rose
[root@bogon ~]# su - rose
[rose@bogon ~]$ cd /test/dir/
[rose@bogon dir]$ cat tom.txt
df -h
[rose@bogon dir]$ echo "uptime" >> tom.txt
-bash: tom.txt: Permission denied [root@bogon dir]# chmod g+w tom.txt
[rose@bogon dir]$ echo "uptime" >> tom.txt [root@bogon dir]# chmod g+x tom.txt
[rose@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
18:15:24 up 3:53, 4 users, load average: 0.00, 0.01, 0.05

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

[root@bogon ~]# su - tom
[tom@bogon ~]$ cd /test/dir/
[tom@bogon dir]$ cat tom.txt
df -h
uptime
[tom@bogon dir]$ echo "free -m" >> tom.txt
[tom@bogon dir]$ ./tom.txt
-bash: ./tom.txt: Permission denied [root@bogon dir]# chmod u+x tom.txt
[tom@bogon dir]$ ./tom.txt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.8G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
18:17:08 up 3:55, 4 users, load average: 0.00, 0.01, 0.05
total used free shared buff/cache available
Mem: 976 129 702 6 145 690
Swap: 2047 0 2047

 

参考链接:http://www.cnblogs.com/linhaifeng/articles/6045600.html

补充:

文件权限

  • read: 能看内容
  • write: 修改内容
  • x: 执行文件

目录权限

  • read: 浏览目录下的子目录名,子文件名
  • write: 创建,重命名,删除子目录名,子文件名
  • x:可以cd切换进入

Linux基础命令(二)的更多相关文章

  1. linux基础命令<二>

    1.关机 init 0   poweroff   halt  shutdown –h   now 2.重启 init 6   reboot  shutdown –r now 3.查询都有那些用户在系统 ...

  2. linux基础命令学习笔记(二)

    linux基础命令学习笔记(二) 1.kill :终止进程  kill pid (唯一标示一个进程) kill -9  强制终止  kill -15 命令未结束不能终止 # ps aux 查看所有进程 ...

  3. Linux基础练习题(二)

    Linux基础练习题(二) 1.复制/etc/skel目录为/home/tuer1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@www ~]# cp -r ...

  4. 运维之Linux基础(二)

    运维之Linux基础(二) 1. file 命令基期用法 2. 文件系统 Linux的文件系统结构是树状结构,所有的文件都在/root跟目录下 /boot:系统启动相关的文件, 如:内核.initrd ...

  5. Linux基础命令-查看基本硬件信息

    Linux基础命令-查看基本硬件信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看CPU信息 [root@node101.yinzhengjie.org.cn ~]# l ...

  6. 运维 04 Shell基础命令(二)

    Shell基础命令(二)   查看Linux的发行版 cat /etc/redhat-release cat /etc/os-release 查看系统用户的id信息 id 用户名 id root id ...

  7. Linux 基础命令及基本目录

    Linux 基础命令及基本目录 一.网卡 1.网卡配置文件路径 ​ /etc/sysconfig/network-scripts/ifcfg-eth0 配置文件: TYPE=Ethernet # 以太 ...

  8. Linux——基础命令用法(上)

    一.Linux基础命令 1.Linux命令行的格式 命令行的格式为:用户名+主机名+当前工作目录 输入内容的命令格式为:命令 [-短选项/--长选项] [参数] [root@localhost ~]# ...

  9. 第四节,Linux基础命令

    第四节,Linux基础命令 命令是系统操作员对系统传入的指令,传入指令后回车,系统接收到指令做出相应的行为 1.查看用户位于系统什么位置 [pmd]检查操作用户位于系统的什么位置 命令         ...

随机推荐

  1. 将HG版本库推送到Git服务器

    如何将HG版本库推送到Git服务器? 目的 习惯使用HG来进行版本管理,但是GitHub代码统计比Bitbucket要丰富,所以准备主力仓库选用Bitbucket,GitHub作为备用仓库. GitH ...

  2. CentOS7:gdb出现没有调试信息:Missing Separate debuginfos

    现在刚刚开始学习用gdb调试程序,结果:在centos下,出现这样的错误: gdb在调试程序时候提示 Missing separate debuginfos, use: debuginfo-insta ...

  3. 已安装 SQL Server 2005 Express 工具。若要继续,请删除 SQL Server 2005 Express 工具

    数据库安装sql server2008R2时遇到. 安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Serv ...

  4. linux学习笔记4--命令mkdir

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. mkdir命令用来创建目录.该命令创建由dirname命名 ...

  5. uva11383 Golden Tiger Claw 深入理解km算法

    /** 题目: uva11383 Golden Tiger Claw 深入理解km算法 链接:https://vjudge.net/problem/UVA-11383 题意:lv 思路:lrj训练指南 ...

  6. 【iOS与EV3混合机器人编程系列之四】iOS_WiFi_EV3_Library 剖析之中的一个:WiFi UDP和TCP

    在上一篇文章中.我们通过编写EV3 Port Viewer项目实现了iOS监測EV3的实时端口数据. 程序最核心的部分就是我们的开源码库iOS_WiFi_EV3_Library. 那么,在本文中,我们 ...

  7. sublime3 10款必备插件

    http://www.cnblogs.com/lhb25/p/10-essential-sublime-text-plugins.html

  8. Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc. (Or rather, the lack thereof)

    http://darksleep.com/player/JavaAndUnsignedTypes.html —————————————————————————————————————————————— ...

  9. C0301 代码块{}的使用,重定向, 从文件中读取行

    #!/bin/bash # 从 /etc/fstab 中读行 File=/etc/fstab {     read line1     read line2 } < $File # {}代码块, ...

  10. cocos2dx-是男人就坚持20s 练手项目

    前言 前段时间心血来潮看了下app游戏方面的东西 ,对比了下各种技术和市场招聘情况,赶脚cocos2dx在2D游戏方向还算是大有所为,遂找了几个基础教程看看了解了解.并附上一个简单demo作为成果 准 ...