Linux 練習 安全加固SELinux

2021-10-07 11:51:54 字數 3345 閱讀 5838

1、啟用 selinux 策略並安裝 httpd 服務,改變**的預設主目錄為 /website,新增 selinux 檔案標籤規則,使**可訪問;

# 安裝 httpd

# 建立 /website 及首頁檔案

[root@localhost ~]

# mkdir /website

[root@localhost ~]

# echo selinux > /website/index.html

# 修改 /website 目錄及檔案的 selinux 屬性

# 修改 httpd 配置

# 重啟服務

# 訪問

[root@localhost ~]

# curl 127.0.0.1

selinux

2、修改上述**的 http 埠為 9527,增加 selinux 埠標籤,使**可訪問;
# 修改監聽埠

# 安裝支援 semanage 的包

[root@localhost ~]

# yum install -y policycoreutils-python

# 新增埠

# 重啟 httpd

# 訪問

[root@localhost ~]

# curl 127.0.0.1:9527

selinux

3、啟用相關的 selinux 布林值,使上述**的使用者 student 的家目錄可通過 http 訪問;
# 檢視是否載入 userdir_modle 模組

## 設定主機名,否則無法查詢

[root@localhost ~]

# hostnamectl set-hostname web.solin.com

## 查詢

# 建立使用者

[root@web ~]

# useradd student

# 建立 public_html 目錄

[root@web ~]

# mkdir /home/student/public_html

# 建立 index.html 檔案

[root@web ~]

# echo student home web > /home/student/public_html/index.html

# 設定acl許可權

[root@web ~]

# setfacl -m u:apache:x /home/student

## 檢視設定的acl許可權

[root@web ~]

# getfacl /home/student

getfacl: removing leading '/' from absolute path names

# file: home/student

# owner: student

# group: student

user::rwx

user:apache:--x

group::---

mask::--x

other::---

# 修改配置檔案

## userdir disabled 改為 userdir public_html

## 新增以下內容

>

require all granted

# 設定 selinux 許可權

[root@web ~]

# chcon -r -t httpd_sys_content_t /home/student/

4、編寫指令碼 selinux.sh,實現開啟或禁用 selinux 功能。
#!/bin/bash

if[ $# -eq 0 ];then

echo 請輸入引數,on 為啟用,off為禁用。

elif[[

$1=~ [oo]

[nn]]]

;then

sed -i "s/^selinux=[[:alpha:]].*/selinux=enforcing/" /etc/selinux/config

echo selinux 已啟用,重啟後生效。

elif[[

$1=~ [oo]

[ff]

[ff]]]

;then

sed -i "s/^selinux=[[:alpha:]].*/selinux=disabled/" /etc/selinux/config

echo selinux 已禁用,重啟後生效。

else

echo 引數錯誤,未做任何設定。

fi

[root@localhost ~]

# chmod +x selinux.sh

# 啟用

[root@localhost ~]

# ./selinux.sh on

selinux 已啟用,重啟後生效。

# 禁用

[root@localhost ~]

# ./selinux.sh off

selinux 已禁用,重啟後生效。

LINUX安全加固操作

1.禁止ctrl alt delete組合鍵重啟系統 vi etc inittab ca ctrlaltdel sbin shutdown t3 r now 如果還存在下面的檔案,則需要注釋掉這兩行 vi etc init control alt delete.conf start on contr...

Linux 系統安全加固

1,變更預設的ssh服務埠,禁止root使用者遠端連線 1 2 3 4 5 6 7 root ljohn cp etc ssh sshd config etc ssh sshd config.bak root ljohn vim etc ssh sshd config port 10022 ssh連...

資訊保安 安全加固

為了防止黑客獲取伺服器中 php 版本資訊,如x powered by php 5.3.7,最好關閉顯示 php 版本資訊,在配置檔案中追加以下資訊 expose php off預設情況下,php錯誤資訊會將程式出錯的原因顯示到瀏覽器上,容易造成敏感資訊洩露。關閉錯誤顯示 display error...