作业:
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文件的内容。
步骤:1, 创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创 建 一个index.html文件;
[root@first ~]# mkdir -pv /www/{name,https}
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/https'
[root@first ~]# touch /www/{name,https}/index.html
[root@first ~]# tree /www
/www
├── https
│ └── index.html
└── name
└── index.html
2 directories, 2 files
2,使用vim命令将主机名写入/www/name/index.html中;
[root@first ~]# vim /www/name/index.html
[root@first ~]# cat /www/name/index.html
rhelo1
3,使用vim命令将当前主机的IP地址写入/www/https/index.html中;
[root@first ~]# vim /www/https/index.html
[root@first ~]# cat /www/https/index.html
192.168.206.129
步骤:1,将/www目录和name,https目录的所属者修改为web用户
[root@first ~]# useradd web
[root@first ~]# chown -R web /www/{name,https}
[root@first ~]# ll -d /www/{name,https}
drwxr-xr-x. 2 web root 24 3月 23 14:54 /www/https
drwxr-xr-x. 2 web root 24 3月 23 14:46 /www/name
[root@first ~]# chown -R web /www
[root@first ~]# ll -d /www
drwxr-xr-x. 4 web root 31 3月 23 14:43 /www
2, 将/www/name和/www/https的所属者的权限给全
[root@first ~]# chmod 4777 /www/{name,https}
[root@first ~]# ll -d /www/{name,https}
drwsrwxrwx. 2 web root 24 3月 23 14:54 /www/https
drwsrwxrwx. 2 web root 24 3月 23 14:46 /www/name
步骤:1,给文件所属组root设置权限为rwx,给其他用户设置权限为---
[root@first ~]# chmod 4770 /www/{name,https}
2,将tom和jerry 用户添加到root组中
[root@first ~]# useradd tom
[root@first ~]# useradd jerry
[root@first ~]# gpasswd -a tom root
正在将用户“tom”加入到“root”组中
[root@first ~]# gpasswd -a jerry root
正在将用户“jerry”加入到“root”组中
[root@first ~]# id tom
用户id=1003(tom) 组id=1003(tom) 组=1003(tom),0(root)
[root@first ~]# id jerry
用户id=1004(jerry) 组id=1004(jerry) 组=1004(jerry),0(root)
步骤:1,创建/log目录
[root@first ~]# mkdir /log
2, 复制/var/log/messages和/var/log/cron文件到/log目录
[root@first ~]# cp /var/log/{messages,cron} /log
[root@first ~]# tree /log
/log
├── cron
└── messages
0 directories, 2 files
3,使用acl命令为日志文件对指定用户admin指定权限
[root@first ~]# setfacl -m u:admin:r /var/log/{cron,messages}
[root@first ~]# ll -d /var/log/{messages,cron}
-rw-r-----+ 1 root root 1048 3月 23 15:50 /var/log/cron
-rw-r-----+ 1 root root 256724 3月 23 15:55 /var/log/messages
步骤:1,复制/etc/ssh/sshd_config文件到/ssh目录
[root@first ~]# mkdir /ssh
[root@first ~]# cp /etc/ssh/sshd_config /ssh
[root@first ~]# tree /ssh
/ssh
└── sshd_config
0 directories, 1 file
2.使用acl命令为/ssh/sshd_config文件对指定用户admin指定权限,使它可以查看并修改文件内容
[root@first ~]# setfacl -m u:admin:rwx /ssh/sshd_config
步骤:1,创建/ssh/sshd文件和/ssh/config文件
[root@first ~]# touch /ssh/{sshd,config}
2,将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中
[root@first ~]# grep -v ^$ /ssh/sshd_config >> /ssh/sshd
(将过滤的空行反向,重定向到/ssh/sshd中)
3,将sshd_config文件中的非空行和非#号开头的行写入config文件中
[root@first ~]# grep -v ^$ /ssh/sshd|grep -v ^[#]>>/ssh/config
[root@first ~]# cat /ssh/config
Include /etc/ssh/sshd_config.d/*.conf
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp /usr/libexec/openssh/sftp-server
4,admin 可以查看sshd文件和config文件的内容。
因为这两个文件对其他用户有读的权限,所以,admin用户可以查看这两个文件