当前位置: 首页 > article >正文

Linux作业2——有关文件系统权限的练习


1、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
#创建/www目录,在/www目录下新建name和https目录
[root@rhcsa0306 ~]# mkdir -pv /www/{name,https}

#​在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
[root@rhcsa0306 ~]# echo rhcsa0306 > /www/name/index.html
[root@rhcsa0306 ~]# echo 192.168.15.129 > /www/https/index.html

#查看index.html文件内容
[root@rhcsa0306 ~]# cat /www/name/index.html
rhcsa0306
[root@rhcsa0306 ~]# cat /www/https/index.html
192.168.15.129

 

2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限。
#新建用户web
[root@rhcsa0306 ~]# useradd web

#递归修改/www及其里面的目录文件的所属者为web
[root@rhcsa0306 ~]# chown -R web /www

#查看
[root@rhcsa0306 ~]# ll /www
总用量 0
drwxr-xr-x. 2 web root 24  3月 23 14:46 https
drwxr-xr-x. 2 web root 24  3月 23 14:45 name
3、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
#添加用户tom和jerry
[root@rhcsa0306 ~]# useradd tom
[root@rhcsa0306 ~]# useradd jerry

#设置其他用户没有任何权限
[root@rhcsa0306 ~]# chmod o-r /www/{https,name}
[root@rhcsa0306 ~]# chmod o-x /www/{https,name}

#查看
[root@rhcsa0306 ~]# ll /www
总用量 0
drwxr-x---. 2 web root 24  3月 23 14:46 https
drwxr-x---. 2 web root 24  3月 23 14:45 name
#通过acl设置tom和jerry在name、https目录下的权限为rwx
[root@rhcsa0306 ~]# setfacl -m u:tom:rwx /www/name
[root@rhcsa0306 ~]# setfacl -m u:tom:rwx /www/https
[root@rhcsa0306 ~]# setfacl -m u:jerry:rwx /www/https
[root@rhcsa0306 ~]# setfacl -m u:jerry:rwx /www/name

 查看ACL权限

 

4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
#新建用户admin
[root@rhcsa0306 ~]# useradd admin

#创建/log,目录
[root@rhcsa0306 ~]# mkdir /log
#将/var/log/messages /var/log/cron 复制到 /log
[root@rhcsa0306 ~]# cp /var/log/messages /var/log/cron /log

#查看/log的权限
[root@rhcsa0306 ~]# ll /log
总用量 488
-rw-------. 1 root root   3252  3月 23 15:32 cron
-rw-------. 1 root root 495380  3月 23 15:32 messages

#修改others对于/log及其子文件的权限
[root@rhcsa0306 ~]# chmod -R o=rx /log

#查看
[root@rhcsa0306 ~]# ll /log
总用量 488
-rw----r-x. 1 root root   3252  3月 23 15:32 cron
-rw----r-x. 1 root root 495380  3月 23 15:32 messages
5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。
#创建一个新目录/ssh
[root@rhcsa0306 ~]# mkdir /ssh

#将/etc/ssh/sshd_config 复制到 /ssh
[root@rhcsa0306 ~]# cp /etc/ssh/sshd_config /ssh

#查看是否复制成功
[root@rhcsa0306 ~]# ll /ssh
总用量 4
-rw-------. 1 root root 3667  3月 23 15:48 sshd_config

#修改用户admin对于该文件的权限
[root@rhcsa0306 ~]# setfacl -m u:admin:rwx /ssh/sshd_config

  查看ACL权限

 

6、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。
#将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中
[root@rhcsa0306 ~]# grep -v ^$ /ssh/sshd_config > /ssh/sshd
#将sshd_config文件中的非空行和非#号开头的行写入config文件中
[root@rhcsa0306 ~]# grep -v ^# /ssh/sshd > /config

 登录admin账号,查看sshd以及config文件内容,检查是否有r权限


http://www.kler.cn/a/597829.html

相关文章:

  • 物化视图详解:数据库性能优化的利器
  • 美制 / 英制单位换算/公制/帝国制 单位转换速查表
  • 某地基坑及周边建筑物自动化监测项目
  • ctfshow——web入门166~170
  • Can通信流程
  • 蓝桥杯11届 门牌制作
  • k8s问题排查
  • 表达式括号匹配(stack)(信息学奥赛一本通-1353)
  • Android笔记之项目引用第三方库(如:Github等)
  • 施耐德 Unity Pro 项目配置
  • 前后端开发中,图片上传到不同格式(二进制数据ORbase64编码)
  • AI比人脑更强,因为被植入思维模型【17】万物联系思维模型
  • Unity | 游戏数据配置
  • 如何在Linux CentOS上安装和配置Redis
  • Okhttp响应Json数据升级版源代码
  • JS 算术运算符
  • 在 coc.nvim 插件中,自动补全时,候选词后面的 大写字母
  • 【机器学习】使用Python Spark MLlib进行预测模型训练
  • 【uniapp】内容瀑布流
  • 系统架构设计知识体系总结