【无标题】

1、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。

 

 [root@localhost ~]# mkdir /ww
 [root@localhost ~]# mkdir -pv /www/name /www/https
 mkdir: 已创建目录 '/www/name'
 mkdir: 已创建目录 '/www/https'
 [root@yuanandzhen ~]# cd /www/name
 [root@localhost name]# touch index.html
 [root@localhost name]# cd /www/https
 [root@localhost https]# touch index.html
 [root@localhost https]# cd /www/name
 [root@localhost name]# echo "yuanandzhen" > /www/name/index.html
[root@localhost ~]# ip a | grep 'inet'
     inet 127.0.0.1/8 scope host lo
     inet6 ::1/128 scope host 
     inet 192.168.254.128/24 brd 192.168.254.255 scope global dynamic noprefixroute ens160
     inet6 fe80::20c:29ff:fe11:c56a/64 scope link noprefixroute 
[root@localhost ~]# ip a | grep 'inet'| cut -d "/" -f1
     inet 127.0.0.1
     inet6 ::1
     inet 192.168.254.128
     inet6 fe80::20c:29ff:fe11:c56a
[root@localhost ~]#ip a | grep 'inet'| cut -d "/" -f1 | grep "192"    inet 192.168.254.128
 [root@localhost ~]# ip a | grep 'inet'| cut -d "/" -f1 | grep "192"| cut -d " " -f6
 192.168.254.128
[root@localhost ~]#echo "192.168.254.128" > /www/https/index.html
[root@localhost ~]# cat /www/https/index.html
 192.168.254.128
[root@localhost ~]# cat /www/name/index.html

 


 ​
[root@localhost ~]#tree
 .
 ├── https
 │   └── index.html
 └── name
     └── index.html

2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限

 

[root@localhost ~]# useradd web
 [root@localhost ~]# chown -R web:web /www
 [root@localhost ~]# ll -d /www
 drwxr-xr-x. 4 web web 31  3月 22 15:08 /www
 [root@localhost ~]# chmod -R 700 /www
 [root@localhost ~]# ll -d /www
 drwx------. 4 web web 31  3月 22 15:08 /www
 # 所有者web用户有读写执行的权限,所属组和其他用户没有任何权限
 ​
 #展示结果:
 [root@localhost ~]# ll -d /www
 drwx------. 4 web web 31  3月 22 15:08 /www
 [root@localhost ~]# ll -d /www/name
 drwxrwx---. 2 root cam 24  3月 22 15:10 /www/name
 [root@localhost ~]# ll -d /www/https
 drwxrwx---. 2 root cam 24  3月 22 15:11 /www/https

 

3、tom和jerry(用户)可以在name和https目录下新建和删除文件,其他用户没有任何权限。

 

 [root@localhost  ~]# useradd tom

 [root@localhost  ~]# useradd jerry

 [root@localhost  ~]# groupadd cam

 ​

 [root@localhost  ~]# useradd -aG cam tom

 [root@localhost  ~]# useradd -aG cam jerry

 ​

 [root@localhost  ~]# chown -R web:cam  /www/name /www/https

 ​

 [root@localhost  ~]# ll -d /www /www/name /www/https

 drwx------. 4 web web 31  3月 22 15:08 /www

 drwxrwx---. 2 web cam 24  3月 22 15:11 /www/https

 drwxrwx---. 2 web cam 24  3月 22 15:10 /www/name

 ​

 [root@localhost  ~]# chmod -R 2770 /www/name /www/https

 ​

 [root@localhost  ~]# ll -d /www /www/name /www/https

 drwx------. 4 web web 31  3月 22 15:08 /www

 drwxrws---. 2 web cam 24  3月 22 15:11 /www/https

 drwxrws---. 2 web cam 24  3月 22 15:10 /www/name

4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。

 

 [root@localhost  ~]# mkdir -p /log

 [root@localhost  ~]# cp /var/log/messages /log

 [root@localhost  ~]# cp /var/log/cron /log/

 [root@localhost  ~]# useradd admin

 [root@localhost  ~]# groupadd abc

 [root@localhost  ~]# usermod -aG abc admin

 [root@localhost  ~]# chown -R root:abc /log/messages

 [root@localhost  ~]# chown -R root:abc /log/cron

 [root@localhost  ~]# chown root:logview /log

 [root@localhost  ~]# chmod 750 /log

 ​

 [root@localhost  ~]# chmod 640 /log/messages

 [root@localhost  ~]# chmod 640 /log/cron

 [root@localhost  ~]#

 ​

 #展示结果

 [root@localhost  ~]# su admin

 [admin@yuanandzhen root]$ cat /log/messages

 Mar 22 14:28:36 yuanandzhen systemd[1]: Starting SSSD Kerberos Cache Manager...

 [admin@yuanandzhen root]$ echo '123' >> /log/messages

 bash: /log/messages: 权限不够

5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。

 

 [root@localhost  ~]# mkdir -p /ssh

 [root@localhost  ~]# cp /etc/ssh/sshd_config /ssh

 cp:是否覆盖'/ssh/sshd_config'?

 [root@localhost  ~]# useradd admin

 useradd:用户“admin”已存在

 ​

 [root@localhost  ~]# chown admin:admin /ssh

 [root@localhost  ~]# chmod 700 /ssh

 ​

 [root@localhost  ~]# chown admin:admin /ssh/sshd_config

 [root@localhost  ~]# chmod 600 /ssh/sshd_config

 [root@localhost  ~]#

 [root@localhost  ~]# ll -d /ssh/sshd_config

 drw-------. 2 admin admin 6  3月 10 23:23 /ssh/sshd_config

 [root@localhost  ~]# su admin

 [admin@yuanandzhen root]$ cat /ssh/sshd_config

 ​

 [admin@yuanandzhen root]$ echo "123" >> /ssh/sshd_config

 ​

 [admin@yuanandzhen root]$ ll -d /ssh/sshd_config

 drw-------. 2 admin admin 6  3月 10 23:23 /ssh/sshd_config

6、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。

 

 [root@localhost  ~]# grep -v ^$ /ssh/sshd_config > /ssh/sshd

 [root@localhost  ~]# vim /ssh/sshd

 ​

 [root@localhost  ~]# grep -v ^$ /ssh/sshd_config |grep -v ^# > /ssh/config

 [root@localhost  ~]# vim /ssh/config

 ​

 [root@localhost  ~]# chown admin:admin /ssh/sshd /ssh/config

 [root@localhost  ~]# chmod 644 /ssh/sshd /ssh/config

 ​

 [root@localhost  ~]# ll -d  /ssh/sshd /ssh/config

 -rw-r--r--. 1 admin admin 3667  3月 22 16:18 /ssh/config

 -rw-r--r--. 1 admin admin 3643  3月 22 16:16 /ssh/sshd

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值