• 《linux系统及其编程》实验课记录(五)


    实验 5:权限的设置和更改

    实验环境:

    安装了 Red Hat Enterprise Linux 6.0 可运行系统,并且是成功验证系统。有另外一个无特权用户 student,密码 student 的账户存在,还有一个无特权的用户 visitor,密码 password的账户存在。

     

    实验目标:

    了解 linux 的安全模型,熟悉用户账号的组群帐号,设置并修改文件权限。

     

    实验背景:

    在 Linux 系统中,各个用户(除超级用户外)的空间之间是隔离的,一个用户是不能进入其他用户的注册空间的。通常普通用户可以通过超级用户在/usr 目录下建立共享的用户目录,

    然后将该共享目录的属主权移交给普通用户。普通用户可将该目录可设置成允许同组用户访问,也可以设置成允许所有用户访问。并在该目录中提供允许共享的文件。

     

    实验要求:

    1、转换用户帐号,查看 id 值

    2、使用 chown 修改文件属主

    3、使用 chmod 采用两种不同方法修改文件权限

    4、使用 umask 修改默认的权限

     

    实验详解:

    1、使用口令 password 登录为用户 visitor。如果你使用的是图形化环境,点击[应用程序(Applications)]->[附件(System Tools)]->[终端(Terminal)]来打开终端:

     

    2、登录到系统之后,你应该就位于你的主目录中。使用”id”命令来查看你的相关信息:

    [student@desktopX ~]$ id

    uid=501(visitor) gid=501(visitor) group=501(visitor)

    „„

    [student@desktopX ~]$ pwd

    /home/visitor

     

     

     

    3、运行 su – student 命令来转换成用户 student,在运行上一步:

    [student@desktopX ~]$ id

    uid=500(visitor) gid=500(visitor) group=500(visitor)

    „„

    [student@desktopX ~]$ pwd

    /home/student

    思考:为什么我们要用 su -而不直接用 su 。

     

     

     

    4、现在切换到 root 用户,在/usr 中创建两个文件夹,分别为 student 和 visitor:

    [student@desktopX ~]$ su -

    Password:

    [root@desktopX ~]# cd /usr

    [root@desktopX usr]# mkdir student visitor

    [root@desktopX usr]# ls –ld student visitor

     

     

     

    5、使用 chown 命令来修改这两个文件夹的属主:

    [root@desktopX usr]# chown student:student student

    [root@desktopX usr]# chown visitor:visitor visitor

     

     

     

    6、回到 student 文件夹,用 student 账户创建两个文本文件,分别为 tf1 和 tf2,并赋予

    不同的权限:

    [student@desktopX student]$ cat >tf1

    This file is for all user

    [student@desktopX student]$ cat >tf2

    This file is for the users in the same groups

    [student@desktopX student]$ ls –l tf1 tf2

     

    [student@desktopX student]$ chmod 750 tf2

    [student@desktopX student]$ ls –l tf1 tf2

     

     

     

    7、切换到 visitor 用户,分别访问刚才创建的两个文件 tf1 和 tf2:

    [student@desktopX student]$ su visitor

    Password:

    [visitor@desktopX student]$ cat tf1

    This file is for all user

    [visitor@desktopX student]$ cat tf2

    cat: tf2: Permission denied

     

     

     

     

     

     

    8、切换到 root 用户,使用 chmod 命令增加 visitor 的访问权限:

    [visitor@desktopX student]$ su

    [root@ desktopX student]# chmod o+r tf2

     

     

     

    9、回到 visitor 用户,继续访问 tf2:

    [visitor@desktopX student]$ cat tf2

    This file is for the users in the same groups

     

     

     

    10、使用 umask 修改文件的默认权限:

    [student@desktopX student]$ umask 0002

    [student@desktopX student]$ mkdir dir1

    [student@desktopX student]$ umask –p 007

    [student@desktopX student]$ mkdir dir2

    [student@desktopX student]$ ls –ld dir1 dir2

     

     

     

    这时候如果切换到 visitor 用户访问 dir2 将会提示权限不够

    [visitor@desktopX student]$ cd dir2

    dir2: .: Permission denied

     

     

    Freecode : www.cnblogs.com/yym2013

  • 相关阅读:
    (二)ElasticSearch-Rest命令操作
    (一)ElasticSearch介绍
    (四)SpringCloudAlibaba处理分布式事务-Seata
    网络设备及组网知识
    GITLAB使用
    Ionic APP开发
    开发工具快捷键大全
    web socket接口测试 Jmeter压力测试工具
    VMware Workstation pro无法在Windows上运行,检查可在Windows上运行的此应用的更新版本
    克隆管理员账号
  • 原文地址:https://www.cnblogs.com/yym2013/p/3652843.html
Copyright © 2020-2023  润新知