RHCSA

rhcsa

3. 调试selinux

准备工作
[root@SYL6 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabl>
   Active: inactive (dead)
     Docs: man:httpd.service(8)
[root@SYL6 ~]# systemctl enable --now httpd
[root@SYL6 ~]# cd /var/www/
[root@SYL6 www]# ls
cgi-bin  html
[root@SYL6 www]# cd html/
[root@SYL6 html]# ls
[root@SYL6 html]# echo '12346' > index.html
[root@SYL6 html]# ls
index.html
[root@SYL6 html]# cd /etc/httpd/
[root@SYL6 httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run  state
[root@SYL6 httpd]# cd conf/
[root@SYL6 conf]# ls
httpd.conf  magic
[root@SYL6 conf]# vim httpd.conf 
[root@SYL6 conf]# cd
    
    
[root@SYL6 ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@SYL6 ~]# 

考试需要查看监听的端口号为多少,再将对应的端口号(82端口)设置为httpd的标准端口
    -a,--add             添加 port 对象类型的记录
    -t TYPE, --type TYPE  对象的 SELinux 类型
    -p PROTO, --proto PROTO
                        指定端口(TCP|UDP)的协议或指定节点(IPv4|IPv6)的互联网协议。
[root@SYL6 ~]# semanage port -l|grep http
http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989
[root@SYL6 ~]# semanage port -a -t http_port_t -p tcp 82
[root@SYL6 ~]# semanage port -l|grep http
http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      82, 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989
[root@SYL6 ~]# systemctl start httpd
[root@SYL6 ~]# 

放行端口号
[root@SYL6 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 port port=82 protocol=tcp accept' --permanent
success
[root@SYL6 ~]# firewall-cmd --reload
success
[root@SYL6 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="0.0.0.0/0" port port="82" protocol="tcp" accept
[root@SYL6 ~]# 
放行协议,不用做
[root@SYL6 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 service name=http accept' --permanent

访问成功
[root@SYL6 ~]# curl 192.168.232.134:82
12346
[root@SYL6 ~]#       

4. 创建用户账号

1)名为admins的组

2)用户harry,其附属组为admins

3)用户natasha,其附属组还属于admins

4)用户alice,没有可交互的登录Shell,且不属于admins组

5)harry、natasha、alice的密码都应该是redhat

-g<群组>:指定用户所属的群组;
-G<群组>:指定用户所属的附加群组;
-m:自动建立用户的登入目录;
-M:不要自动建立用户的登入目录;
-r:建立系统帐号;
-s<shell>:指定用户登入后所使用的shell-u<uid>:指定用户id

[root@SYL6 ~]# useradd admins
[root@SYL6 ~]# grep admins /etc/passwd
admins:x:1000:1000::/home/admins:/bin/bash
[root@SYL6 ~]# grep admins /etc/group
[root@SYL6 ~]# useradd -G admins harry
[root@SYL6 ~]# useradd -G admins natasha
[root@SYL6 ~]# useradd -s /sbin/nologin alice
[root@SYL6 ~]# grep alice /etc/passwd
alice:x:1003:1003::/home/alice:/sbin/nologin
[root@SYL6 ~]# id alice
uid=1003(alice) gid=1003(alice) groups=1003(alice)
[root@SYL6 ~]# 
[root@SYL6 ~]# echo 'redhat'|passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@SYL6 ~]# echo 'redhat'|passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@SYL6 ~]# echo 'redhat'|passwd --stdin alice
Changing password for user alice.
passwd: all authentication tokens updated successfully.
[root@SYL6 ~]# 

5. 配置计划任务

配置计划任务,以用户harry的身份每5分钟执行一次命令 echo wangqing。
[root@SYL6 ~]# crontab -u harry -e
no crontab for harry - using an empty one
crontab: installing new crontab
[root@SYL6 ~]# crontab -u harry -l
*/5 * * * * /usr/bin/echo 'wangqing'
[root@SYL6 ~]# 

分时日月周
*/2 每隔2分钟
10-12 10129,11 9点多,11点多

配置计划任务,以用户harry的身份每天14:23分执行一次命令 echo hello
[root@SYL3 ~]# cron
crond     cronnext  crontab   
[root@SYL3 ~]# crontab -u harry -e
no crontab for harry - using an empty one
crontab: installing new crontab
[root@SYL3 ~]# crontab -u harry -l
23 14 * * * /usr/bin/echo hello
[root@SYL3 ~]# 

6. 创建共享目录

创建具有以下特点的共用目录:
1/home/tools的所有组是admins
2)此目录能被admins组的成员读取、写入和访问,除root外其他用户没有这些权限
3)在此目录下创建的文件,其组的所有权自动设置为admins组
[root@SYL6 ~]# mkdir /home/tools
[root@SYL6 ~]# ll /home/
total 0
drwx------. 2 admins  admins  62 May 14 11:24 admins
drwx------. 2 alice   alice   62 May 14 11:30 alice
drwx------. 2 harry   harry   62 May 14 11:27 harry
drwx------. 2 natasha natasha 62 May 14 11:28 natasha
drwxr-xr-x. 2 root    root     6 May 14 11:38 tools
[root@SYL6 ~]# chown -R .admins /home/tools
[root@SYL6 ~]# chmod 2770 /home/tools/
[root@SYL6 ~]# ll /home/
total 0
drwx------. 2 admins  admins  62 May 14 11:24 admins
drwx------. 2 alice   alice   62 May 14 11:30 alice
drwx------. 2 harry   harry   62 May 14 11:27 harry
drwx------. 2 natasha natasha 62 May 14 11:28 natasha
drwxrws---. 2 root    admins   6 May 14 11:38 tools
[root@SYL6 ~]# 

7. 时间客户端

vim /etc/chrony.conf
server classroom.example.com iburs
systemctl enable --now chronyd
systemctl restart chronyd
chronyc sources

9. 配置文件权限

[root@SYL6 ~]# cp /etc/fstab /var/tmp/
[root@SYL6 ~]# ll /var/tmp/fstab 
-rw-r--r--. 1 root root 579 May 14 11:57 /var/tmp/fstab
[root@SYL6 ~]# setfacl -m u:harry:rw- /var/tmp/fstab 
[root@SYL6 ~]# setfacl -m u:natasha:--- /var/tmp/fstab 
[root@SYL6 ~]# getfacl /var/tmp/fstab 
getfacl: Removing leading '/' from absolute path names
# file: var/tmp/fstab
# owner: root
# group: root
user::rw-
user:harry:rw-
user:natasha:---
group::r--
mask::rw-
other::r--

[root@SYL6 ~]# 

10. 配置用户账户

创建用户wangqing,其用户ID为2020,此用户的密码应当是redhat
[root@SYL6 ~]# useradd -u 2020 wangqing
[root@SYL6 ~]# echo 'redhat'|passwd --stdin wangqing
Changing password for user wangqing.
passwd: all authentication tokens updated successfully.
[root@SYL6 ~]# 

11. 查找文件

找出/etc/目录下大小超过5MB的文件,并将其复制到/root/findfiles目录下

[root@SYL6 ~]# mkdir /root/findfiles
[root@SYL6 ~]# find /etc/ -size +5M -exec cp -r {} /root/findfiles/ \;
[root@SYL6 ~]# find /root/findfiles/ -size +5M
/root/findfiles/hwdb.bin
/root/findfiles/policy.31
[root@SYL6 ~]# du -sh findfiles/
19M     findfiles/
[root@SYL6 ~]# 
[root@SYL6 findfiles]# du -sh hwdb.bin 
11M     hwdb.bin
[root@SYL6 findfiles]# du -sh policy.31 
8.2M    policy.31
[root@SYL6 findfiles]# 

请把系统上拥有者为tammy用户的所有文件,并将其拷贝到/root/findfiles目录中。
[root@servera ~]# mkdir /root/findfiles
[root@servera ~]# find / -user tammy -exec cp -r {} /root/findfiles/ \;
[root@servera ~]# ll findfiles/
-size : +10k 大于10K -10 小于10k
find / -size +10k -size -20k 大于10k小于20k的文件
-perm : 755 /2000 查找用sgid权限的文件
find / -perm /2000

-name 'filename'    //对文件名作精确匹配.支持glob通配符机制
-iname 'filename'   //文件名匹配时不区分大小写
-regex pattern      //基于正则表达式进行文件名匹配.以pattern \
-user username          //根本属主来查找
-group groupname        //根据属组来查找
-uid        //根据UID进行查找,当用户被删除以后文件的属主会变为此用户的UID
-gid        //根据GID进行查找,当用户被删除以后文件的属组会变为此用户的GID
-nouser     //查找没有属主的文件.用户被删除的情况下产生的文件,只有uid没有属主
-nogroup    //查找没有属组的文件.组被删除的情况下产生的文件,只有gid没有属组
-type       //根据文件类型来查找(f,d,c,b,l,p,s)
-size      //+表示大于,-表示小于
-mtime      //修改时间
-ctime      //改变时间
-atime      //访问时间
+5      //5天前
-5      //5天以内
-mmin       //多少分钟修改过
-cmin       //多少分钟改变过
-amin       //多少分钟访问过
+5      //5分钟前
-5      //5分钟以内
-perm mode      //根据权限精确查找
-perm -mode     //文件权限能完全包含此mode时才符合条件
-perm /mode     //9位权限中有任何一位权限匹配都视为符合查找条件

12. 查找字符串

找出文件/etc/man_db.conf中包含字符串sbin的所有行,将其按原始顺序导入到文件/root/out.txt中,文件/root/out.txt中不得包含空行

[root@SYL6 ~]# grep sbin /etc/man_db.conf 
MANPATH_MAP     /sbin                   /usr/share/man
MANPATH_MAP     /usr/sbin               /usr/share/man
MANPATH_MAP     /usr/local/sbin         /usr/local/man
MANPATH_MAP     /usr/local/sbin         /usr/local/share/man
MANPATH_MAP     /opt/sbin               /opt/man
[root@SYL6 ~]# grep sbin /etc/man_db.conf > /root/out.txt
[root@SYL6 ~]# grep sbin /root/out.txt 
MANPATH_MAP     /sbin                   /usr/share/man
MANPATH_MAP     /usr/sbin               /usr/share/man
MANPATH_MAP     /usr/local/sbin         /usr/local/man
MANPATH_MAP     /usr/local/sbin         /usr/local/share/man
MANPATH_MAP     /opt/sbin               /opt/man
[root@SYL6 ~]# 

13. 创建归档

jcf bz2 
Jcf xz 
zcf gzip

tar -jcf /root/backup.tar.bz2 /usr/local/
file backup.tar.bz2 

14. 配置root密码

重启系统
移动光标,按e
移动到linux末尾+ rd.break
按 ctrl+x 执行
mount -o remount,rw /sysroot/
chroot /sysroot/
echo '123456'|passwd --stdin root
touch /.autorelabel
exit x2

20. 配置系统调优

[root@SYL6 ~]# tuned-adm recommend
virtual-guest
[root@SYL6 ~]# tuned-adm profile virtual-guest
[root@SYL6 ~]# tuned-adm list

21. 配置umask值

设置natasha用户创建的目录权限默认为733,文件权限为622,要求永久生效

[root@SYL3 ~]# useradd natasha
[root@SYL3 ~]# echo '123456'|passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@SYL3 ~]# su - natasha
[natasha@SYL3 ~]$ ls .bash
.bash_logout   .bash_profile  .bashrc        
[natasha@SYL3 ~]$ vim .bashrc 
[natasha@SYL3 ~]$ cat .bashrc 
# .bashrc

umask 044
# Source global definitions
[natasha@SYL3 ~]$ source .bashrc 
[natasha@SYL3 ~]$ mkdir test
[natasha@SYL3 ~]$ touch fike
[natasha@SYL3 ~]$ ll
total 0
-rw--w--w-. 1 natasha natasha 0 Jun 19 11:18 fike
drwx-wx-wx. 2 natasha natasha 6 Jun 19 11:18 test

22. 配置sudo提权

允许admins组的成员可以以root的身份执行任何命令,并且不需要密码。

[root@SYL3 ~]# visudo
## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
[root@SYL3 ~]# cat /etc/sudoers.d/admins
%admins        ALL=(root)       NOPASSWD: ALL
[root@SYL3 ~]# 
[root@SYL3 ~]# su - harry
Last login: Sun Jun 19 11:11:06 CST 2022 on pts/2
[harry@SYL3 ~]$ sudo useradd test1
[harry@SYL3 ~]$ id test1
uid=1006(test1) gid=1006(test1) groups=1006(test1)
[harry@SYL3 ~]$ 

23. 设置密码默认策略

为新创建的用户设置密码策略,要求创建用户时,密码默认20 天后过期

[root@SYL3 ~]# ls /etc/login.defs 
/etc/login.defs
[root@SYL3 ~]# vim /etc/login.defs 
[root@SYL3 ~]# cat /etc/login.defs|grep PASS_MAX_DAYS
#       PASS_MAX_DAYS   Maximum number of days a password may be used.
PASS_MAX_DAYS   20
[root@SYL3 ~]# useradd test2
[root@SYL3 ~]# cat /etc/shadow|grep test2
test2:!!:19162:0:20:7:::
[root@SYL3 ~]# 

你可能感兴趣的:(服务器,网络,linux)