Linux系統(tǒng)安全加固技巧_第1頁(yè)
Linux系統(tǒng)安全加固技巧_第2頁(yè)
Linux系統(tǒng)安全加固技巧_第3頁(yè)
Linux系統(tǒng)安全加固技巧_第4頁(yè)
Linux系統(tǒng)安全加固技巧_第5頁(yè)
已閱讀5頁(yè),還剩282頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Linux系統(tǒng)安全加固技巧一、概述

Linux系統(tǒng)作為服務(wù)器和個(gè)人計(jì)算機(jī)的重要操作系統(tǒng),其安全性至關(guān)重要。安全加固是指通過(guò)一系列配置和優(yōu)化措施,提高系統(tǒng)的抗攻擊能力,減少安全漏洞。本文檔將介紹Linux系統(tǒng)安全加固的常用技巧,包括用戶管理、系統(tǒng)配置、軟件更新、防火墻設(shè)置等方面。通過(guò)這些方法,可以有效提升Linux系統(tǒng)的整體安全性。

---

二、用戶管理

(一)強(qiáng)化用戶密碼策略

1.設(shè)置密碼復(fù)雜度要求

通過(guò)修改`/etc/pam.d/common-password`文件,啟用密碼復(fù)雜度策略。

-添加或修改以下行:

```

passwordrequisitepam_pwquality.soretry=3minlen=8difok=3ucredit=-1lcredit=-1dcredit=-1maxrepeat=3enforce_for_root

```

-參數(shù)說(shuō)明:

-`retry`:密碼嘗試次數(shù)

-`minlen`:最小長(zhǎng)度

-`difok`:必須包含不同字符數(shù)

2.定期更換密碼

修改`/etc/login.defs`文件中的`PASS_MAX_DAYS`和`PASS_MIN_DAYS`參數(shù),強(qiáng)制用戶定期更換密碼。

```

PASS_MAX_DAYS90密碼有效期90天

PASS_MIN_DAYS7最短使用間隔7天

```

(二)限制root用戶直接登錄

1.禁用root遠(yuǎn)程登錄

編輯`/etc/ssh/sshd_config`文件,修改以下配置:

```

PermitRootLoginno

```

-保存并重啟SSH服務(wù):

```

sudosystemctlrestartsshd

```

2.創(chuàng)建特權(quán)用戶

為日常操作創(chuàng)建具有sudo權(quán)限的用戶,避免頻繁使用root賬號(hào)。

```

sudouseradd-mprivileged_user

sudopasswdprivileged_user

sudovisudo添加以下行:

%privileged_userALL=(ALL)NOPASSWD:ALL

```

---

三、系統(tǒng)配置

(一)關(guān)閉不必要的服務(wù)

1.識(shí)別并禁用多余服務(wù)

使用`systemctl`命令查看所有服務(wù)狀態(tài):

```

sudosystemctllist-units--type=service--state=running

```

-禁用不必要的服務(wù):

```

sudosystemctldisable<service_name>

sudosystemctlstop<service_name>

```

2.最小化系統(tǒng)安裝

避免安裝非必要的軟件包,減少攻擊面。

```

sudoaptremove--purge<unnecessary_package>

```

(二)內(nèi)核參數(shù)優(yōu)化

1.增強(qiáng)網(wǎng)絡(luò)防護(hù)

編輯`/etc/sysctl.conf`文件,添加或修改以下參數(shù):

```

net.ipv4.ip_forward=0禁用IP轉(zhuǎn)發(fā)

net.ipv4.conf.all.accept_source_route=0禁用源路由

net.ipv4.tcp_syncookies=1啟用SYNCookies

```

-應(yīng)用配置:

```

sudosysctl-p

```

2.限制進(jìn)程創(chuàng)建

修改`/etc/security/limits.conf`文件,限制root用戶可創(chuàng)建的進(jìn)程數(shù):

```

softnproc65535

rootsoftnproc1000

```

---

四、軟件更新與漏洞管理

(一)自動(dòng)化更新策略

1.配置unattended-upgrades

安裝并配置自動(dòng)更新:

```

sudoaptinstallunattended-upgrades

sudodpkg-reconfigureunattended-upgrades

```

-編輯`/etc/apt/apt.conf.d/50unattended-upgrades`文件,啟用自動(dòng)安裝安全更新:

```

Unattended-Upgrade::Allowed-Origins{"origin='Ubuntu'";"origin='Debian'";};

```

2.定期檢查更新

手動(dòng)檢查可用更新:

```

sudoaptupdate&&sudoaptupgrade

```

(二)使用漏洞掃描工具

1.安裝OpenVAS

-安裝OpenVAS:

```

sudoaptinstallopenvas

```

-啟動(dòng)并初始化數(shù)據(jù)庫(kù):

```

sudogvm-setup

```

-運(yùn)行掃描:

```

sudogvm-check-update

sudogvm-run--scan-all

```

2.分析掃描結(jié)果

-登錄OpenVASWeb界面(默認(rèn)端口9392),查看高風(fēng)險(xiǎn)漏洞并修復(fù)。

---

五、防火墻與網(wǎng)絡(luò)隔離

(一)配置iptables

1.基礎(chǔ)防火墻規(guī)則

-清空現(xiàn)有規(guī)則:

```

sudoiptables-F

```

-設(shè)置默認(rèn)策略:

```

sudoiptables-PINPUTDROP

sudoiptables-PFORWARDDROP

sudoiptables-POUTPUTACCEPT

```

-允許本地回環(huán):

```

sudoiptables-AINPUT-ilo-jACCEPT

```

2.開放必要端口

-允許SSH(默認(rèn)22端口):

```

sudoiptables-AINPUT-ptcp--dport22-jACCEPT

```

-允許HTTP(80)和HTTPS(443):

```

sudoiptables-AINPUT-ptcp--dport80-jACCEPT

sudoiptables-AINPUT-ptcp--dport443-jACCEPT

```

(二)使用firewalld

1.啟用并配置firewalld

```

sudosystemctlenablefirewalld

sudosystemctlstartfirewalld

```

-添加端口:

```

sudofirewall-cmd--permanent--add-port=80/tcp

sudofirewall-cmd--permanent--add-port=443/tcp

```

-重載配置:

```

sudofirewall-cmd--reload

```

2.區(qū)域管理

-查看默認(rèn)區(qū)域:

```

sudofirewall-cmd--get-active-zones

```

-將接口加入信任區(qū)域(如內(nèi)網(wǎng)接口):

```

sudofirewall-cmd--zone=trusted--add-interface=eth0

```

---

六、日志監(jiān)控與審計(jì)

(一)配置syslog

1.安裝syslog-ng

```

sudoaptinstallsyslog-ng

```

-編輯`/etc/syslog-ng/syslog-ng.conf`文件,配置日志轉(zhuǎn)發(fā):

```

sources_local{system();internal();};

destinationd_remote{tcp("0"port(514));};

logl{source(s_local);destination(d_remote);};

```

-重啟服務(wù):

```

sudosystemctlrestartsyslog-ng

```

(二)使用auditd

1.啟用審計(jì)服務(wù)

```

sudoaptinstallauditd

sudosystemctlenableauditd

```

-創(chuàng)建審計(jì)規(guī)則(示例:監(jiān)控root登錄):

```

sudoauditctl-w/home/root-pwarx-kroot_login

```

2.查看審計(jì)日志

```

sudoausearch-kroot_login

```

---

七、總結(jié)

Linux系統(tǒng)安全加固是一個(gè)持續(xù)的過(guò)程,需要結(jié)合用戶管理、系統(tǒng)配置、軟件更新、防火墻設(shè)置和日志監(jiān)控等多方面措施。通過(guò)嚴(yán)格執(zhí)行上述技巧,可以有效降低系統(tǒng)被攻擊的風(fēng)險(xiǎn),保障數(shù)據(jù)和服務(wù)的安全。建議定期復(fù)查和更新安全策略,以應(yīng)對(duì)新的威脅。

---

二、用戶管理(續(xù))

(三)最小權(quán)限原則

1.精簡(jiǎn)用戶權(quán)限

-為每個(gè)用戶分配完成其任務(wù)所必需的最小權(quán)限集。

-使用`chmod`和`chown`限制文件訪問(wèn)權(quán)限。

-示例:為Web服務(wù)器用戶(如`www-data`)僅授權(quán)訪問(wèn)特定目錄:

```

sudochown-Rwww-data:www-data/var/www/html

sudochmod-R755/var/www/html

sudofind/var/www/html-typed-execchmod750{}\;

sudofind/var/www/html-typef-execchmod640{}\;

```

2.禁用或刪除閑置賬戶

-定期審計(jì)用戶賬戶,禁用或刪除長(zhǎng)期未使用的賬戶。

-查找閑置賬戶:

```

sudolastb|grep-v'root'|awk'{print$1}'|sort|uniq-d

sudoawk-F':''{if($3>999&&$3<20000)print$1}'/etc/passwd

```

-禁用賬戶:

```

sudousermod-L<username>

```

-刪除賬戶:

```

sudodeluser<username>

```

(四)使用SELinux增強(qiáng)隔離

1.啟用SELinux

-檢查SELinux狀態(tài):

```

sudosestatus

```

-如果未啟用,修改`/etc/selinux/config`文件:

```

SELINUX=enforcing

SELINUXTYPE=targeted

```

-重啟系統(tǒng)或重啟服務(wù):

```

sudoreboot

或sudosystemctlreboot

```

2.配置SELinux策略

-查看默認(rèn)策略:

```

sudosemanageport-l

```

-開放特定端口(示例:開放Nginx端口80):

```

sudosemanageport-a-thttp_port_t-ptcp80

```

-設(shè)置文件上下文(示例:將文件設(shè)置為httpd系統(tǒng)):

```

sudochcon-thttpd_sys_content_t/var/www/html/index.html

```

---

三、系統(tǒng)配置(續(xù))

(三)系統(tǒng)日志安全

1.配置syslog服務(wù)器

-選擇一臺(tái)可信服務(wù)器作為日志收集點(diǎn)。

-在目標(biāo)服務(wù)器上安裝syslog服務(wù)(如`rsyslog`):

```

sudoaptinstallrsyslog

```

-編輯`/etc/rsyslog.conf`文件,配置日志轉(zhuǎn)發(fā):

```

.@@0:514

```

-重啟服務(wù):

```

sudosystemctlrestartrsyslog

```

2.限制日志訪問(wèn)

-修改日志文件權(quán)限,僅允許授權(quán)用戶訪問(wèn)。

-示例:設(shè)置`/var/log/syslog`權(quán)限:

```

sudochmod600/var/log/syslog

sudochownroot:root/var/log/syslog

```

(四)磁盤安全

1.使用LVM加密

-創(chuàng)建加密卷(示例:使用LUKS):

```

sudocryptsetupluksFormat/dev/sdb1

sudocryptsetupopen/dev/sdb1my_encrypted_volume

```

-在LVM中創(chuàng)建物理卷和邏輯卷:

```

sudopvcreate/dev/mapper/my_encrypted_volume

sudovgcreateencrypted_vg/dev/mapper/my_encrypted_volume

sudolvcreate-L20G-ndata_lvmencrypted_vg

```

-格式化并掛載:

```

sudomkfs.ext4/dev/encrypted_vg/data_lvm

sudomount/dev/encrypted_vg/data_lvm/mnt/encrypted

```

2.定期磁盤檢查

-編輯`/etc/fstab`文件,添加檢查選項(xiàng):

```

/dev/sda1/bootext4defaults,noatime11

/dev/sda2/ext4defaults,noatime,check=none01

```

-手動(dòng)檢查磁盤:

```

sudofsck/dev/sda2

```

---

四、軟件更新與漏洞管理(續(xù))

(三)容器化應(yīng)用安全

1.使用Docker安全最佳實(shí)踐

-從官方倉(cāng)庫(kù)拉取鏡像:

```

dockerpullubuntu:latest

```

-避免使用root用戶運(yùn)行容器:

```

dockerrun-d--user$(id-u):$(id-g)ubuntu:latest/bin/bash

```

-啟用鏡像掃描:

```

dockerscanubuntu:latest

```

2.容器網(wǎng)絡(luò)隔離

-使用Docker網(wǎng)絡(luò)創(chuàng)建專用網(wǎng)絡(luò):

```

dockernetworkcreatemy_secure_network

dockerrun--networkmy_secure_network-dubuntu:latest

```

-配置端口映射時(shí)限制來(lái)源IP:

```

dockerrun-d-p80:80--networkmy_secure_network--restartalwaysnginx

僅允許本地訪問(wèn):

sudoiptables-AINPUT-ptcp--dport80-s-jACCEPT

```

(四)使用自動(dòng)化工具

1.配置Ansible進(jìn)行批量加固

-安裝Ansible:

```

sudoaptinstallansible

```

-創(chuàng)建Playbook(示例:設(shè)置密碼策略):

```yaml

---

-name:Configurepasswordpolicy

hosts:all

become:yes

tasks:

-name:Setpasswordcomplexity

lineinfile:

path:/etc/pam.d/common-password

regexp:'^password.pam_pwquality.so'

line:'passwordrequisitepam_pwquality.soretry=3minlen=8difok=3ucredit=-1lcredit=-1dcredit=-1maxrepeat=3enforce_for_root'

-name:Setpasswordexpiration

lineinfile:

path:/etc/login.defs

regexp:'^PASS_MAX_DAYS'

line:'PASS_MAX_DAYS90'

lineinfile:

path:/etc/login.defs

regexp:'^PASS_MIN_DAYS'

line:'PASS_MIN_DAYS7'

```

-執(zhí)行Playbook:

```

ansible-playbook-iinventory加固playbook.yml

```

---

五、防火墻與網(wǎng)絡(luò)隔離(續(xù))

(三)VPN與遠(yuǎn)程訪問(wèn)

1.配置OpenVPN

-安裝OpenVPN:

```

sudoaptinstallopenvpnopenvpn-systemd-resolved

```

-創(chuàng)建配置文件(示例:`/etc/openvpn/server.conf`):

```

devtun

protoudp

port1194

remote-cert-tlsserver

ca/etc/openvpn/ca.crt

cert/etc/openvpn/server.crt

key/etc/openvpn/server.key

client-config-dir/etc/openvpn/ccd

push"route"

keepalive10120

comp-lzo

useropenvpn

groupopenvpn

persist-key

persist-tun

status/var/log/openvpn/openvpn-status.log

```

-啟動(dòng)服務(wù):

```

sudosystemctlstartopenvpn@server

sudosystemctlenableopenvpn@server

```

2.配置客戶端

-為客戶端生成配置文件(`client.ovpn`):

```

client

devtun

protoudp

remote<server_ip>1194

remote-cert-tlsserver

caca.crt

certclient.crt

keyclient.key

<ca>

</ca>

route

keepalive10120

comp-lzo

```

(四)入侵檢測(cè)系統(tǒng)(IDS)

1.安裝Suricata

-安裝Suricata:

```

sudoaptinstallsuricata

```

-下載規(guī)則集:

```

sudosuricata-updatedownloadrules

sudosuricata-updateinstallrules

```

-編輯配置文件(`/etc/suricata/suricata.conf`):

```

outputalert:file/var/log/suricata/alert.log

outputlog:file/var/log/suricata/spool.log

```

-啟動(dòng)服務(wù):

```

sudosystemctlstartsuricata

sudosystemctlenablesuricata

```

2.配置Web界面

-安裝Web界面(如Sonar):

```

sudoaptinstallsuricata-webui

```

-訪問(wèn)界面:

```

http://<server_ip>:13241

```

-配置網(wǎng)絡(luò)接口進(jìn)行監(jiān)控:

```

sudosuricata-cmd-c/etc/suricata/suricata.conf-e-ieth0

```

---

六、日志監(jiān)控與審計(jì)(續(xù))

(三)使用Logwatch

1.安裝Logwatch

-安裝Logwatch:

```

sudoaptinstalllogwatch

```

-編輯配置文件(`/etc/logwatch/conf/logwatch.conf`):

```

Output=mail

MailTo=admin@

Format=text

MailFrom=logwatch@

Detail=High

MailServer=localhost

```

-每天自動(dòng)生成報(bào)告:

```

sudosystemctlenablelogwatch

```

2.自定義報(bào)告

-創(chuàng)建自定義插件(如`/usr/share/logwatch/plugins/custom/`):

```bash

示例:檢查特定日志文件

!/bin/sh

LOGFILE="/var/log/auth.log"

echo"CustomLogwatchPlugin"

echo"------------------------"

grep"Failedpassword"$LOGFILE|wc-l

```

-確保腳本可執(zhí)行:

```

sudochmod+x/usr/share/logwatch/plugins/custom/custom.sh

```

(四)使用Prometheus與Grafana

1.安裝Prometheus

-安裝Prometheus:

```

sudoaptinstallprometheusprometheus-node-exporter

```

-配置Prometheus(`/etc/prometheus/prometheus.yml`):

```yaml

global:

scrape_interval:15s

scrape_configs:

-job_name:'localhost'

static_configs:

-targets:['localhost:9100']

-job_name:'sysdig'

static_configs:

-targets:['0:2023']

labels:

job:'sysdig'

__metrics_path__'/metrics'

__address__':2023'

cluster:'sysdig'

relabel_configs:

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

-action:labelmap

regex:__.__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs:

-targets:['0:2023']

relabel_configs:

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

metric_path:'/metrics'

params:

format:[json]

static_configs

-targets:['0:2023']

relabel_configs

-action:labelmap

regex:__.__

-action:replace

regex:^job:.$

replacement:'sysdig'

target_label:__job__

-action:replace

regex:^cluster:.$

replacement:''

target_label:__cluster__

scrape_interval:5s

honor_labels:true

一、概述

Linux系統(tǒng)作為服務(wù)器和個(gè)人計(jì)算機(jī)的重要操作系統(tǒng),其安全性至關(guān)重要。安全加固是指通過(guò)一系列配置和優(yōu)化措施,提高系統(tǒng)的抗攻擊能力,減少安全漏洞。本文檔將介紹Linux系統(tǒng)安全加固的常用技巧,包括用戶管理、系統(tǒng)配置、軟件更新、防火墻設(shè)置等方面。通過(guò)這些方法,可以有效提升Linux系統(tǒng)的整體安全性。

---

二、用戶管理

(一)強(qiáng)化用戶密碼策略

1.設(shè)置密碼復(fù)雜度要求

通過(guò)修改`/etc/pam.d/common-password`文件,啟用密碼復(fù)雜度策略。

-添加或修改以下行:

```

passwordrequisitepam_pwquality.soretry=3minlen=8difok=3ucredit=-1lcredit=-1dcredit=-1maxrepeat=3enforce_for_root

```

-參數(shù)說(shuō)明:

-`retry`:密碼嘗試次數(shù)

-`minlen`:最小長(zhǎng)度

-`difok`:必須包含不同字符數(shù)

2.定期更換密碼

修改`/etc/login.defs`文件中的`PASS_MAX_DAYS`和`PASS_MIN_DAYS`參數(shù),強(qiáng)制用戶定期更換密碼。

```

PASS_MAX_DAYS90密碼有效期90天

PASS_MIN_DAYS7最短使用間隔7天

```

(二)限制root用戶直接登錄

1.禁用root遠(yuǎn)程登錄

編輯`/etc/ssh/sshd_config`文件,修改以下配置:

```

PermitRootLoginno

```

-保存并重啟SSH服務(wù):

```

sudosystemctlrestartsshd

```

2.創(chuàng)建特權(quán)用戶

為日常操作創(chuàng)建具有sudo權(quán)限的用戶,避免頻繁使用root賬號(hào)。

```

sudouseradd-mprivileged_user

sudopasswdprivileged_user

sudovisudo添加以下行:

%privileged_userALL=(ALL)NOPASSWD:ALL

```

---

三、系統(tǒng)配置

(一)關(guān)閉不必要的服務(wù)

1.識(shí)別并禁用多余服務(wù)

使用`systemctl`命令查看所有服務(wù)狀態(tài):

```

sudosystemctllist-units--type=service--state=running

```

-禁用不必要的服務(wù):

```

sudosystemctldisable<service_name>

sudosystemctlstop<service_name>

```

2.最小化系統(tǒng)安裝

避免安裝非必要的軟件包,減少攻擊面。

```

sudoaptremove--purge<unnecessary_package>

```

(二)內(nèi)核參數(shù)優(yōu)化

1.增強(qiáng)網(wǎng)絡(luò)防護(hù)

編輯`/etc/sysctl.conf`文件,添加或修改以下參數(shù):

```

net.ipv4.ip_forward=0禁用IP轉(zhuǎn)發(fā)

net.ipv4.conf.all.accept_source_route=0禁用源路由

net.ipv4.tcp_syncookies=1啟用SYNCookies

```

-應(yīng)用配置:

```

sudosysctl-p

```

2.限制進(jìn)程創(chuàng)建

修改`/etc/security/limits.conf`文件,限制root用戶可創(chuàng)建的進(jìn)程數(shù):

```

softnproc65535

rootsoftnproc1000

```

---

四、軟件更新與漏洞管理

(一)自動(dòng)化更新策略

1.配置unattended-upgrades

安裝并配置自動(dòng)更新:

```

sudoaptinstallunattended-upgrades

sudodpkg-reconfigureunattended-upgrades

```

-編輯`/etc/apt/apt.conf.d/50unattended-upgrades`文件,啟用自動(dòng)安裝安全更新:

```

Unattended-Upgrade::Allowed-Origins{"origin='Ubuntu'";"origin='Debian'";};

```

2.定期檢查更新

手動(dòng)檢查可用更新:

```

sudoaptupdate&&sudoaptupgrade

```

(二)使用漏洞掃描工具

1.安裝OpenVAS

-安裝OpenVAS:

```

sudoaptinstallopenvas

```

-啟動(dòng)并初始化數(shù)據(jù)庫(kù):

```

sudogvm-setup

```

-運(yùn)行掃描:

```

sudogvm-check-update

sudogvm-run--scan-all

```

2.分析掃描結(jié)果

-登錄OpenVASWeb界面(默認(rèn)端口9392),查看高風(fēng)險(xiǎn)漏洞并修復(fù)。

---

五、防火墻與網(wǎng)絡(luò)隔離

(一)配置iptables

1.基礎(chǔ)防火墻規(guī)則

-清空現(xiàn)有規(guī)則:

```

sudoiptables-F

```

-設(shè)置默認(rèn)策略:

```

sudoiptables-PINPUTDROP

sudoiptables-PFORWARDDROP

sudoiptables-POUTPUTACCEPT

```

-允許本地回環(huán):

```

sudoiptables-AINPUT-ilo-jACCEPT

```

2.開放必要端口

-允許SSH(默認(rèn)22端口):

```

sudoiptables-AINPUT-ptcp--dport22-jACCEPT

```

-允許HTTP(80)和HTTPS(443):

```

sudoiptables-AINPUT-ptcp--dport80-jACCEPT

sudoiptables-AINPUT-ptcp--dport443-jACCEPT

```

(二)使用firewalld

1.啟用并配置firewalld

```

sudosystemctlenablefirewalld

sudosystemctlstartfirewalld

```

-添加端口:

```

sudofirewall-cmd--permanent--add-port=80/tcp

sudofirewall-cmd--permanent--add-port=443/tcp

```

-重載配置:

```

sudofirewall-cmd--reload

```

2.區(qū)域管理

-查看默認(rèn)區(qū)域:

```

sudofirewall-cmd--get-active-zones

```

-將接口加入信任區(qū)域(如內(nèi)網(wǎng)接口):

```

sudofirewall-cmd--zone=trusted--add-interface=eth0

```

---

六、日志監(jiān)控與審計(jì)

(一)配置syslog

1.安裝syslog-ng

```

sudoaptinstallsyslog-ng

```

-編輯`/etc/syslog-ng/syslog-ng.conf`文件,配置日志轉(zhuǎn)發(fā):

```

sources_local{system();internal();};

destinationd_remote{tcp("0"port(514));};

logl{source(s_local);destination(d_remote);};

```

-重啟服務(wù):

```

sudosystemctlrestartsyslog-ng

```

(二)使用auditd

1.啟用審計(jì)服務(wù)

```

sudoaptinstallauditd

sudosystemctlenableauditd

```

-創(chuàng)建審計(jì)規(guī)則(示例:監(jiān)控root登錄):

```

sudoauditctl-w/home/root-pwarx-kroot_login

```

2.查看審計(jì)日志

```

sudoausearch-kroot_login

```

---

七、總結(jié)

Linux系統(tǒng)安全加固是一個(gè)持續(xù)的過(guò)程,需要結(jié)合用戶管理、系統(tǒng)配置、軟件更新、防火墻設(shè)置和日志監(jiān)控等多方面措施。通過(guò)嚴(yán)格執(zhí)行上述技巧,可以有效降低系統(tǒng)被攻擊的風(fēng)險(xiǎn),保障數(shù)據(jù)和服務(wù)的安全。建議定期復(fù)查和更新安全策略,以應(yīng)對(duì)新的威脅。

---

二、用戶管理(續(xù))

(三)最小權(quán)限原則

1.精簡(jiǎn)用戶權(quán)限

-為每個(gè)用戶分配完成其任務(wù)所必需的最小權(quán)限集。

-使用`chmod`和`chown`限制文件訪問(wèn)權(quán)限。

-示例:為Web服務(wù)器用戶(如`www-data`)僅授權(quán)訪問(wèn)特定目錄

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論