作业一:
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. 多线程-ConcurrentHashMap(JDK1.8)

    前言 HashMap非线程安全的,HashTable是线程安全的,所有涉及到多线程操作的都加上了synchronized关键字来锁住整个table,这就意味着所有的线程都在竞争一把锁,在多线程的环境下 ...

  2. ActiveMQ从源代码构建

    众多开源项目.我们一般都是直接拿过来用之而后快. 只是我们也应该知道这些项目是怎样从源代码构建而来的. 既然代码是写出来的,就不能避免有BUG存在,话说没有完美的软件,也没有无漏洞的程序. 事实上从源 ...

  3. locationInView和translationInView的区别

      1  translationInView是UIPanGestureRecognizer下面的一个属性 locationInView则是UIGestureRecognizer下面的属性 2  tra ...

  4. 进程隐藏与进程保护(SSDT Hook 实现)(三)

    文章目录: 1. 引子: 2. 获取当前系统下所有进程: 3. 服务管理(安装,启动,停止,卸载): 4. 应用程序和内核程序通信: 5. 小结: 1. 引子: 关于这个 SSDT Hook 实现进程 ...

  5. linux学习笔记18---目录结构

    对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统至关重要,下面 ...

  6. PHP文件包含

    今天突然发现这个东西有好多奇怪的东西,特别写一下记一下 测试用的1.txt及phpinfo.php内容都是phpinfo() 截断: 好多.和好多./截断:这里不测试了,摘自代码审计一书,5.2可用, ...

  7. (转)64位开源处理器Rocket的源代码简单介绍

    转载地址: http://blog.csdn.net/leishangwen/article/details/46604819 最近大概阅读了一下UCB发布的Rocket处理器的源码,对源代码各个文件 ...

  8. Hadoop项目实战

    这个项目是流量经营项目,通过Hadoop的离线数据项目. 运营商通过HTTP日志,分析用户的上网行为数据,进行行为轨迹的增强. HTTP数据格式为: 流程: 系统架构: 技术选型: 这里只针对其中的一 ...

  9. Enable Authentication on MongoDB

    1.Connect to the server using the mongo shell mongo mongodb://localhost:27017 2.Create the user admi ...

  10. sql把varchar转化为int型

    select Max(convert(int,id))from member_Info;