作业:
1、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限。
3、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。
6、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。
一、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
[root@localhost ~]# mkdir -p /www
[root@localhost ~]# mkdir -p /www/name /www/https
[root@localhost name]# hostname > /www/name/index.html
[root@localhost name]# ip a | grep ens160 | grep inet | cut -d / -f1 | tr -s ' ' | cut -d ' ' -f3 > /www/https/index.html
结果:
[root@localhost name]# cat /www/https/index.html
192.168.23.130
[root@localhost name]# cat index.html
localhost.localdomain
二、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限
[root@localhost ~]# useradd web
[root@localhost ~]# chown -R web:web /www
[root@localhost ~]# chmod -R u=rwx,g=rwx,o=rwx /www
结果:
[root@localhost ~]# ll /www /www/https /www/name -d
drwxrwxrwx. 4 web web 31 3月 23 13:39 /www
drwxrwxrwx. 2 web web 24 3月 23 17:28 /www/https
drwxrwxrwx. 2 web web 24 3月 23 14:13 /www/name
三、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
[root@localhost ~]# useradd tom
[root@localhost ~]# useradd jerry
[root@localhost ~]# groupadd gruop1
[root@localhost ~]# usermod -aG gruop1 tom
[root@localhost ~]# usermod -aG gruop1 jerry
[root@localhost ~]# chown -R web:gruop1 /www/https /www/name
[root@localhost ~]# chmod -R 770 /www/https /www/name
结果:
[root@localhost ~]# ll /www/https /www/name -d
drwxrwxrwx. 2 web gruop1 24 3月 23 17:28 /www/https
drwxrwxrwx. 2 web gruop1 24 3月 23 14:13 /www/name
[root@localhost ~]# ll -d /www/https /www/name
drwxrwx---. 2 web gruop1 24 3月 23 17:28 /www/https
drwxrwx---. 2 web gruop1 24 3月 23 14:13 /www/name
四、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
[root@localhost ~]# mkdir -p /log
[root@localhost ~]# cp /var/log/messages /var/log/cron /log
[root@localhost ~]# groupadd group1
[root@localhost ~]# useradd admin
[root@localhost ~]# usermod -aG group1 admin
[root@localhost ~]# chown root:group1 /log
[root@localhost ~]# chown root:group1 /log/cron /log/messages
[root@localhost ~]# chmod g=r /log/cron /log/messages
结果:
[root@localhost ~]# ll -d /log/cron /log/messages
-rw-r-----. 1 root group1 10870 3月 28 20:55 /log/cron
-rw-r-----. 1 root group1 531083 3月 28 20:55 /log/messages
五、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容
[root@localhost ~]# mkdir -p /ssh
[root@localhost ~]# cp /etc/ssh/sshd_config /ssh
[root@localhost ~]# chown admin:admin /ssh/sshd_config
[root@localhost ~]# chmod u=rw /ssh/sshd_config
结果:
[root@localhost ~]# ll /ssh
总用量 4
-rw-------. 1 admin admin 3667 3月 28 22:13 sshd_config
六、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。
[root@localhost ~]# grep -v ^$ /ssh/sshd_config > /ssh/sshd
[root@localhost ~]# grep -v ^$ /ssh/sshd_config | grep -v ^# > /ssh/config
[root@localhost ~]# chown admin:admin /ssh/sshd /ssh/config
[root@localhost ~]# chmod u=r /ssh/sshd /ssh/config
结果:
[root@localhost ~]# ll -d /ssh/sshd /ssh/config
-r--r--r--. 1 admin admin 126 3月 28 22:40 /ssh/config
-r--r--r--. 1 admin admin 3643 3月 28 22:39 /ssh/sshd
[root@localhost ~]# vim /ssh/sshd