unit6.7.8.10.11

简介:

1.开启 Selinux 的作用

>给程序及程序里面的文件一个安全上下文

2.Selinux关闭时的状况

vim /etc/sysconfig/selinux


selinux 的配置文件

    SELINUX=enforcing   selinux 开启

    SELINUX=disabled    selinux 关闭

getenforce

查看 selinux 状态

[root@dchxmj linux1]# ls

file1  linux1file1  pub

[root@dchxmj linux1]# ls -Z

-rw-r--r-- root root ?                                file1

-rw-r--r-- root root ?                                linux1file1

drwxrwxr-x root root ?                                pub

[root@dchxmj linux1]# 


7

测试:


lftp IP -u username

[kiosk@foundation30 Desktop]$ lftp 172.25.254.130 -u linux1

Password: 

lftp linux1@172.25.254.130:~> ls       

-rw-r--r--    1 0        0               0 Feb 21 08:50 file1

-rw-r--r--    1 0        0               0 Feb 21 07:40 linux1file1

drwxrwxr-x    2 0        0               6 Feb 21 08:28 pub

#所有文件都可以访问到

lftp linux1@172.25.254.130:/> ls -Z

-rw-r--r--    1 0        0               0 Feb 21 08:50 file1

-rw-r--r--    1 0        0               0 Feb 21 07:40 linux1file1

drwxrwxr-x    2 0        0               6 Feb 21 08:28 pub

lftp linux1@172.25.254.130:/> exit

[kiosk@foundation30 Desktop]$ 

3.Selinux 开启时

[root@localhost pub]# ls

file1  linux  linux1

[root@localhost pub]# ls -Z

-rw-r--r--. root root unconfined_u:object_r:mnt_t:s0   file1

drwxr-xr-x. root root unconfined_u:object_r:mnt_t:s0   linux

-rw-r--r--. root root unconfined_u:object_r:public_content_t:s0 linux1

#不符合形式的文件访问不到

[root@localhost pub]#

测试:

[kiosk@foundation30 Desktop]$ lftp 172.25.254.130 

lftp 172.25.254.130:~> ls

drwxr-xr-x    3 0        0              43 Feb 21 09:07 pub

lftp 172.25.254.130:/> cd pub/

lftp 172.25.254.130:/pub> ls

drwxr-xr-x    2 0        0               6 Feb 21 09:04 linux

-rw-r--r--    1 0        0               0 Feb 21 09:05 linux1

lftp 172.25.254.130:/pub> exit

[kiosk@foundation30 Desktop]$ 



4.Selinux对服务的影响


(1).不符合安全上下文的文件访问不到

(2).默认情况下不安全的功能是关闭的

getsebool -a | grep ftp     #查看 ftp 服务功能状态 

setsebool -P ftp_home_dir on    #开启

       -P:表示永久开启

      本地用户默认有写权限



[root@localhost ~]# getsebool -a | grep ftp

`ftp_home_dir --> off`

[root@foundation30 ~]# lftp 172.25.254.130 -u student

Password: 

lftp student@172.25.254.130:~> ls      

-rw-r--r--    1 0        0               0 Feb 22 03:17 file2

drwxr-xr-x    2 0        0               6 Feb 22 01:36 linux1

lftp student@172.25.254.130:~> cd linux1/

lftp student@172.25.254.130:~/linux1> put /etc/passwd

put: Access failed: 553 Could not create file. (passwd)

lftp student@172.25.254.130:~/linux1> exit

[root@foundation30 ~]# lftp 172.25.254.130 -u student

[root@localhost ~]# setsebool -P ftp_home_dir on

[root@localhost ~]# getsebool -a | grep ftp

ftp_home_dir --> on

[root@foundation30 ~]# lftp 172.25.254.130 -u student

Password: 

lftp student@172.25.254.130:~> ls      

-rw-r--r--    1 0        0               0 Feb 22 03:17 file2

drwxr-xr-x    2 0        0               6 Feb 22 01:36 linux1

lftp student@172.25.254.130:~> put /etc/passwd

2367 bytes transferred

lftp student@172.25.254.130:~> exit

[root@foundation30 ~]# 

5.Selinux 日志存放位置

cat /var/log/audit/audit.log #默认位置

setroubleshoot-server.x86_64 

###可以将/var/log/audit/audit.log里面的日志经过处理存放到/var/log/messages



[root@localhost ~]# yum search setroubleshoot

Loaded plugins: langpacks

========================= N/S matched: setroubleshoot ==========================

setroubleshoot-plugins.noarch : Analysis plugins for use with setroubleshoot

setroubleshoot.x86_64 : Helps troubleshoot SELinux problems

setroubleshoot-server.x86_64 : SELinux troubleshoot server


  Name and summary matches only, use "search all" for everything.

[root@localhost ~]# yum install setroubleshoot-server.x86_64  -y



cat /var/log/audit/audit.log

cat /var/log/messages

unit7

1.网络文件系统

如何访问

1)yum install samba-client

2)smbclient -L //ip

3)smbclient //ip/sharename

如何访问

mount //ip/sharename /mountpoint -o username=guest

vim /etc/fstab

//ip/sharename /mountpoint cifs defaults,username=guest 0 0

mount -a

5.NFS如何共享

1)yum       install      nfs-utils       -y

2)vim       /etc/exports

/mnt  *(rw)     ##共享/mnt 所有人可以访问(权限)

3)exportfs  -rv

4)systemctl restart nfs-server

6.NFS如何访问


6.1手动挂载

1)yum        install    nfs-utils   -y       ##安装NFS软件

2)showmount  -e     ip      ##显示共享的目录

3)mount     ip:/sharedir     /mountpoint     ##挂载共享目录到本机

这里写图片描述


6.2自动挂载

1)yum install autofs        ##安装软件

2)systemctl start autofs    ##开启服务

3)cd /net/ip/                   ##进入共享目录

4)vim /etc/autofs.conf      ##修改自动卸载时间单位(妙)

    TIMEOUT=5

6.3自定义挂载方式


mkdir       /nfs/nfs1       ##创建自定义挂载目录

vim /etc/auto.master最终挂载点的上层目录  自策略文件

            /nfs            /etc/auto.nfs

vim 自策略文件(vim /etc/auto.nfs)    

最终挂载点   网络挂载资源

nfs1        172.25.254.250:/nfsshare/nfs1

    *       172.25.254.250:/nfsshare/&


进入nfs1 则自动挂载到nfs1, *和&任意匹配  

    systemctl restart autofs            ##重启服务

cd /nfs/nfs1

unit11系统恢复技术

2.1密码忘记,修改root用户密码


重启,到grub选项菜单,按’e’进入编辑模式。 

这里写图片描述

找到kernel命令行编辑如下图 

这里写图片描述

这里写图片描述

得到一个shell 

这里写图片描述 chroot /sysroot/ 

passwd root 

touch /.autorelabel 

这里写图片描述

按两下ctlr+d或输入两次exit退出重启就可以正常登陆了。


2.2grub文件引导阶段文件丢失


如果/boot/grub2/grub.cfg引导文件丢失,则如图 

这里写图片描述

输入这四条命令,就会重启 

这里写图片描述

进入系统后,在shell输入命令生成缺失的引导文件,系统就修复成功! 

grub2-mkconfig >/boot/grub2/grub.cfg 

这里写图片描述


2.3内核文件丢失


如果系统内核文件丢失,则重启时会如图所示 

这里写图片描述

关机,选择镜像启动<这里用虚拟机做实验> 

 这里写图片描述 

进入界面选择“Rescue Red Hat Enterprise Linux system” 

这里写图片描述 

选择“Troubleshooting” 

这里写图片描述

进入挽救模式,“chroot /mnt/sysimage” 

这里写图片描述

这里写图片描述

这里写图片描述

得到一个shell,执行刚才的命令,重新安装内核安装包


chroot /mnt/sysimage        ##切换到真实根环境

yum install kernel -y       ##安装内核安装包

这里写图片描述

按两下ctlr+d或输入两次exit退出,关掉镜像启动,开启硬盘启动,就可以正常登陆。

2.4 initramfs-‘uname- r’.img文件丢失

这里写图片描述

chroot /mnt/sysimage        ##切换到真实根环境

cd /boot/                       ##进入boot目录

mkinitrd initramfs-`uname -r`.img  `uname -r`

uname -r                        ##内核版本号

这里写图片描述

按两下ctlr+d或输入两次exit退出,关掉镜像启动,开启硬 盘启动,就可以正常登陆。


2.5误删shell文件,系统恢复

设置镜像启动,进入挽救模式,得到一个shell。 

由于/bin/bash文件缺失,无法使用shell, 

这里写图片描述

cp       /bin/bash /mnt/sysimage/bin/bash   

这里写图片描述

cp       /bin/bash /mnt/sysimage/bin/bash       

按两下ctlr+d或输入两次exit退出,关掉镜像启动,开启硬 盘启动,就可以正常登陆。

2.6系统启动级别文件链接错误


/etc/systemd/system/default.target      ##系统开机链接文件

启动级别共6级

当default.target 链接到别的级别,则系统无法启动到图形界面

default.target -> /lib/systemd/system/graphical.target

这里,systemctl set-default poweroff.target    使其链接为0级别。

则,系统开机就会自动关机。

置镜像启动,进入挽救模式,得到一个shell。输入如下命令。


chroot /mnt/sysimage        ##切换到真实根环境

Rm -fr /etc/systemd/system/default.target

删除错误链接文件


Ln  -s  /usr/lib/systemd/system/graphical.target

etc/systemd/system/default.target       ##建立新的链接文件

这里写图片描述

按两下ctlr+d或输入两次exit退出,关掉镜像启动,开启硬 盘启动,就可以正常登陆。
















本文转自铁骑传说51CTO博客,原文链接:http://blog.51cto.com/ybzbfs/1922005 ,如需转载请自行联系原作者
相关文章
|
存储 缓存 Java
Null Nothing Unit|学习笔记
快速学习 Null Nothing Unit。
103 0
Null Nothing Unit|学习笔记
|
Linux 开发工具
|
Linux 数据安全/隐私保护 Shell
|
开发工具
|
Linux Shell 数据库
|
开发工具 缓存 Linux