作业一:
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. AES_CBC_PKCS5Padding 加密

    在项目中需要对一些关键信息进行传输,但又不能是明文,所以采用此种方式进行加密,另一端再进行解密. AES: 算法 CBC: 模式 ​ 使用CBC模式,需要一个向量iv,可增加加密算法的强度 PKCS5 ...

  2. poj Ping pong LA 4329 (树状数组统计数目)

    Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2302   Accepted: 879 Descript ...

  3. ext,exrReturn新增,修改删除等用

    package cn.edu.hbcf.common.vo; /** * Ext Ajax 返回对象 * * @author * @date 2012-02-21 19:30:00 * */ publ ...

  4. uGUI Anchor

    Anchor定位:inspector面板的Rect Transform组件中PosX左边的方框图标就是设置锚点的,做界面自适应时可定位控件在视图中的位置,与NGUI类似.Anchor+Canvas的C ...

  5. AJax与Jsonp跨域访问

    一.JavaScript的AJax AJAX即"Asynchronous Javascript And XML"(异步JavaScript和XML) 设计AJax使用的一种重要技术 ...

  6. nginx 403 forbidden 二种原因

    nginx 403 forbidden 二种原因 引起nginx 403 forbidden有二种原因,一是缺少索引文件,二权限问题.今天又遇到 了,顺便总结一下. 1,缺少index.html或者i ...

  7. Asp.Net中使用水晶报表

    Asp.Net中使用水晶报表(上) 在我们对VS.Net中的水晶报表(Crystal Reports)进行研究之前,我和我朋友对如何将这个复杂的东东加入我们的Web应用有着非常的好奇心.一周以后,在阅 ...

  8. android 开发积累

    1.ListView滚动黑屏问题 ListView滚动时,数据项变成黑色 问题解决办法:通过添加 android:cacheColorHint = "#00000000" 将背景设 ...

  9. 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...

  10. 【BZOJ】1661: [Usaco2006 Nov]Big Square 巨大正方形(暴力)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1661 暴力大法好... 枚举对角线(注意,一种对角线2种情况就行了,自己想...) 然后可以算出其它 ...